mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
* Reduce object creation during parsing * Rename method to createElement * Make code more efficient? * Update migration guide
5.8 KiB
5.8 KiB
Chart.js 3.x Migration Guide
Chart.js 3.0 introduces a number of breaking changes. Chart.js 2.0 was released in April 2016. In the years since then, as Chart.js has grown in popularity and feature set, we've learned some lessons about how to better create a charting library. In order to improve performance, offer new features, and improve maintainability it was necessary to break backwards compatibility, but we aimed to do so only when necessary.
End user migration
Setup and installation
- Chart.js is no longer providing the
Chart.bundle.jsandChart.bundle.min.js. Please see the installation and integration docs for details on the recommended way to setup Chart.js if you were using these builds. momentis no longer specified as an npm dependency. If you are using the time scale, you must include one of the available adapters and corresponding date library. If you are using a date library other than moment, you no longer need to exclude moment from your build.
Ticks
options.ticks.userCallbackwas renamed tooptions.ticks.callback
Tooltip
xLabelandyLabelwere removed. Please useindexandvalue
Interactions
options.onClickis now limited to the chart area{mode: 'single'}was replaced with{mode: 'nearest', intersect: true}{mode: 'label'}was replaced with{mode: 'index'}modes['X-axis']was replaced with{mode: 'index', intersect: false}
Customizability
customattribute of elements was removed. Please use scriptable options- The
zeroLine*options of axes were removed. Use scriptable scale options instead. - The
hoverproperty of scriptable optionscontextobject was renamed toactiveto align it with the datalabels plugin.
Options
- The dataset option
tensionwas renamed tolineTension scales.[x/y]Axes.barPercentagewas moved to dataset optionbarPercentagescales.[x/y]Axes.barThicknesswas moved to dataset optionbarThicknessscales.[x/y]Axes.categoryPercentagewas moved to dataset optioncategoryPercentagescales.[x/y]Axes.minBarLengthwas moved to dataset optionminBarLengthscales.[x/y]Axes.maxBarThicknesswas moved to dataset optionmaxBarThicknessscales.[x/y]Axes.ticks.beginAtZerowas renamed toscales.[x/y]Axes.beginAtZeroscales.[x/y]Axes.ticks.maxwas renamed toscales.[x/y]Axes.maxscales.[x/y]Axes.ticks.minwas renamed toscales.[x/y]Axes.minscales.[x/y]Axes.ticks.reversewas renamed toscales.[x/y]Axes.reversescales.[x/y]Axes.ticks.suggestedMaxwas renamed toscales.[x/y]Axes.suggestedMaxscales.[x/y]Axes.ticks.suggestedMinwas renamed toscales.[x/y]Axes.suggestedMinscales.[x/y]Axes.time.formatwas renamed toscales.[x/y]Axes.time.parserscales.[x/y]Axes.time.maxwas renamed toscales.[x/y]Axes.maxscales.[x/y]Axes.time.minwas renamed toscales.[x/y]Axes.min
Developer migration
Removed
afterScaleUpdatehelpers.addEventhelpers.aliasPixelhelpers.configMergehelpers.indexOfhelpers.minhelpers.maxhelpers.nextItemhelpers.numberOfLabelLineshelpers.previousItemhelpers.removeEventhelpers.roundedRecthelpers.scaleMergeChart.ControllerChart.chart.chartChart.typesDatasetController.addElementAndResetElement.getAreaElement.heightElement.inLabelRangeLine.calculatePointYScale.getRightValueScale.mergeTicksOptionsScale.ticksAsNumbersScale.handleDirectionalChangesis now privateScale.tickValuesis now private
Removal of private APIs
_model.datasetLabel_model.labelTimeScale.getLabelWidth
Renamed
helpers.clearwas renamed tohelpers.canvas.clearhelpers.drawRoundedRectanglewas renamed tohelpers.canvas.roundedRecthelpers.callCallbackwas renamed tohelpers.callbackhelpers.getValueOrDefaultwas renamed tohelpers.valueOrDefaulthelpers.getValueAtIndexOrDefaultwas renamed tohelpers.valueAtIndexOrDefaulthelpers.easingEffectswas renamed tohelpers.easing.effectshelpers.log10was renamed tohelpers.math.log10Chart.Animation.animationObjectwas renamed toChart.AnimationChart.Animation.chartInstancewas renamed toChart.Animation.chartDatasetController.createMetaDataandDatasetController.createMetaDatasetwere replaced withDatasetController.createElementTimeScale.getLabelCapacitywas renamed toTimeScale._getLabelCapacityTimeScale.tickFormatFunctionwas renamed toTimeScale._tickFormatFunctionTimeScale.getPixelForOffsetwas renamed toTimeScale._getPixelForOffset
Renamed private APIs
helpers._alignPixelwas renamed tohelpers.canvas._alignPixel
Changed
Scales
scale.getLabelForIndexwas replaced byscale.getLabelForValuescale.getPixelForValuenow has only one parameter
Ticks
- When
autoSkipis enabled,scale.ticksnow contains only the non-skipped ticks instead of all ticks. scale.ticksnow contains objects instead of stringsbuildTicksis now expected to return tick objectsafterBuildTicksnow has no parameters like the other callbacksconvertTicksToLabelswas renamed togenerateTickLabels. It is now expected to set the label property on the ticks given as input
Time Scale
getValueForPixelnow returns milliseconds since the epoch
Controllers
Core Controller
- The first parameter to
updateHoverStyleis now an array of objects containing theelement,datasetIndex, andindex
Dataset Controllers
setHoverStylenow additionally takes thedatasetIndexandindex
Interactions
- Interaction mode methods now return an array of objects containing the
element,datasetIndex, andindex