mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
10 KiB
10 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.callbackoptions.ticks.majorandoptions.ticks.minorwere replaced with scriptable options for tick fonts.
Tooltip
xLabelandyLabelwere removed. Please useindexandvalue
Interactions
interactionsare now limited to the chart area{mode: 'label'}was replaced with{mode: 'index'}{mode: 'single'}was replaced with{mode: 'nearest', intersect: true}modes['X-axis']was replaced with{mode: 'index', intersect: false}options.onClickis now limited to the chart area
Customizability
customattribute of elements was removed. Please use scriptable options- The
hoverproperty of scriptable optionscontextobject was renamed toactiveto align it with the datalabels plugin. - The
zeroLine*options of axes were removed. Use scriptable scale options instead.
Defaults
globalnamespace was removed fromdefaults. SoChart.defaults.globalis nowChart.defaultsdefaultprefix was removed from defaults. For exampleChart.defaults.global.defaultColoris nowChart.defaults.colordefaultColorwas renamed tocolordefaultFontColorwas renamed tofontColordefaultFontFamilywas renamed tofontFamilydefaultFontSizewas renamed tofontSizedefaultFontStylewas renamed tofontStyledefaultLineHeightwas renamed tolineHeight
Options
- Dataset options are now configured as
options[type].datasetsrather thanoptions.datasets[type] Polar areastartAngleoption is now consistent withRadar, 0 is at top and value is in degrees. Default is changed from-½πto0.scales.[x/y]Axesarrays were removed. Scales are now configured directly tooptions.scalesobject with the object key being the scale Id.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.maxBarThicknesswas moved to dataset optionmaxBarThicknessscales.[x/y]Axes.minBarLengthwas moved to dataset optionminBarLengthscales.[x/y]Axes.ticks.beginAtZerowas renamed toscales[id].beginAtZeroscales.[x/y]Axes.ticks.maxwas renamed toscales[id].maxscales.[x/y]Axes.ticks.minwas renamed toscales[id].minscales.[x/y]Axes.ticks.reversewas renamed toscales[id].reversescales.[x/y]Axes.ticks.suggestedMaxwas renamed toscales[id].suggestedMaxscales.[x/y]Axes.ticks.suggestedMinwas renamed toscales[id].suggestedMinscales.[x/y]Axes.time.formatwas renamed toscales[id].time.parserscales.[x/y]Axes.time.maxwas renamed toscales[id].maxscales.[x/y]Axes.time.minwas renamed toscales[id].min- The dataset option
tensionwas renamed tolineTension - To override the platform class used in a chart instance, pass
platform: PlatformClassin the config object. Note that the class should be passed, not an instance of the class.
Animations
Animation system was completely rewritten in Chart.js v3. Each property can now be animated separately. Please see animations docs for details.
hover.animationDurationis now configured inanimation.active.durationresponsiveAnimationDurationis now configured inanimation.resize.duration
Developer migration
Removed
Chart.chart.chartChart.ControllerChart.prototype.generateLegendChart.typesChart.Tooltipis now provided by the tooltip plugin. The positioners can be accessed fromtooltipPlugin.positionersDatasetController.addElementAndResetDatasetController.createMetaDataDatasetController.createMetaDatasetElement.getAreaElement.heightElement.initializeElement.inLabelRangehelpers.addEventhelpers.aliasPixelhelpers.configMergehelpers.findIndexhelpers.findNextWherehelpers.findPreviousWherehelpers.indexOfhelpers.lineTohelpers.longestTextwas moved to thehelpers.canvasnamespace and made privatehelpers.maxhelpers.measureTextwas moved to thehelpers.canvasnamespace and made privatehelpers.minhelpers.nextItemhelpers.numberOfLabelLineshelpers.previousItemhelpers.removeEventhelpers.roundedRecthelpers.scaleMergehelpers.whereILayoutItem.minSizeIPlugin.afterScaleUpdate. UseafterLayoutinsteadLine.calculatePointYLogarithmicScale.minNotZeroScale.getRightValueScale.handleDirectionalChangesis now privateScale.longestLabelWidthScale.longestTextCacheis now privateScale.mergeTicksOptionsScale.ticksAsNumbersScale.tickValuesis now private- The tooltip item's
xandyattributes were removed. UsedatasetIndexandindexto get the element and any corresponding data from it
Removal of private APIs
Chart.data.datasets[datasetIndex]._metaElement._ctxElement._modelElement._viewLogarithmicScale._valueOffsetTimeScale._getPixelForOffsetTimeScale.getLabelWidthTooltip._lastActive
Renamed
Chart.Animation.animationObjectwas renamed toChart.AnimationChart.Animation.chartInstancewas renamed toChart.Animation.charthelpers._decimalPlaceswas renamed tohelpers.math._decimalPlaceshelpers.almostEqualswas renamed tohelpers.math.almostEqualshelpers.almostWholewas renamed tohelpers.math.almostWholehelpers.callCallbackwas renamed tohelpers.callbackhelpers.clearwas renamed tohelpers.canvas.clearhelpers.distanceBetweenPointswas renamed tohelpers.math.distanceBetweenPointshelpers.drawRoundedRectanglewas renamed tohelpers.canvas.roundedRecthelpers.getAngleFromPointwas renamed tohelpers.math.getAngleFromPointhelpers.getMaximumHeightwas renamed tohelpers.dom.getMaximumHeighthelpers.getMaximumWidthwas renamed tohelpers.dom.getMaximumWidthhelpers.getRelativePositionwas renamed tohelpers.dom.getRelativePositionhelpers.getStylewas renamed tohelpers.dom.getStylehelpers.getValueAtIndexOrDefaultwas renamed tohelpers.valueAtIndexOrDefaulthelpers.getValueOrDefaultwas renamed tohelpers.valueOrDefaulthelpers.easingEffectswas renamed tohelpers.easing.effectshelpers.log10was renamed tohelpers.math.log10helpers.isNumberwas renamed tohelpers.math.isNumberhelpers.signwas renamed tohelpers.math.signhelpers.retinaScalewas renamed tohelpers.dom.retinaScalehelpers.splineCurvewas renamed tohelpers.curve.splineCurvehelpers.splineCurveMonotonewas renamed tohelpers.curve.splineCurveMonotonehelpers.toDegreeswas renamed tohelpers.math.toDegreeshelpers.toRadianswas renamed tohelpers.math.toRadiansScale.calculateTickRotationwas renamed toScale.calculateLabelRotationTimeScale.getLabelCapacitywas renamed toTimeScale._getLabelCapacityTimeScale.getPixelForOffsetwas renamed toTimeScale._getPixelForOffsetTimeScale.tickFormatFunctionwas renamed toTimeScale._tickFormatFunctionTooltip.options.legendColorBackgroupdwas renamed toTooltip.options.multiKeyBackground
Renamed private APIs
helpers._alignPixelwas renamed tohelpers.canvas._alignPixelhelpers._decimalPlaceswas renamed tohelpers.math._decimalPlaceschart.initializewas renamed tochart._initialize(labeled as private but not named as such)
Changed
Scales
Scale.getLabelForIndexwas replaced byscale.getLabelForValueScale.getPixelForValuenow has only one parameter. For theTimeScalethat parameter must be millis since the epoch
Ticks
Scale.afterBuildTicksnow has no parameters like the other callbacksScale.buildTicksis now expected to return tick objectsScale.convertTicksToLabelswas renamed togenerateTickLabels. It is now expected to set the label property on the ticks given as inputScale.ticksnow contains objects instead of strings- When the
autoSkipoption is enabled,Scale.ticksnow contains only the non-skipped ticks instead of all ticks.
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
updateElementwas replaced withupdateElementsnow taking the elements to update, thestartindex, andmodesetHoverStyleandremoveHoverStylenow additionally take thedatasetIndexandindex
Interactions
- Interaction mode methods now return an array of objects containing the
element,datasetIndex, andindex
Layout
ILayoutItem.updateno longer has a return value
Helpers
Canvas Helper
- The second parameter to
drawPointis now the full options object, sostyle,rotation, andradiusare no longer passed explicitly
Platform
Chart.platformis no longer the platform object used by charts. It contains only a single configuration option,disableCSSInjection. Every chart instance now has a separate platform instance.Chart.platformsis an object that contains two usable platform classes,BasicPlatformandDomPlatform. It also containsBasePlatform, a class that all platforms must extend from.- If the canvas passed in is an instance of
OffscreenCanvas, theBasicPlatformis automatically used.