mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-07 20:59:08 +02: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.js
andChart.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. moment
is 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.userCallback
was renamed tooptions.ticks.callback
options.ticks.major
andoptions.ticks.minor
were replaced with scriptable options for tick fonts.
Tooltip
xLabel
andyLabel
were removed. Please useindex
andvalue
Interactions
interactions
are 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.onClick
is now limited to the chart area
Customizability
custom
attribute of elements was removed. Please use scriptable options- The
hover
property of scriptable optionscontext
object was renamed toactive
to align it with the datalabels plugin. - The
zeroLine*
options of axes were removed. Use scriptable scale options instead.
Defaults
global
namespace was removed fromdefaults
. SoChart.defaults.global
is nowChart.defaults
default
prefix was removed from defaults. For exampleChart.defaults.global.defaultColor
is nowChart.defaults.color
defaultColor
was renamed tocolor
defaultFontColor
was renamed tofontColor
defaultFontFamily
was renamed tofontFamily
defaultFontSize
was renamed tofontSize
defaultFontStyle
was renamed tofontStyle
defaultLineHeight
was renamed tolineHeight
Options
- Dataset options are now configured as
options[type].datasets
rather thanoptions.datasets[type]
Polar area
startAngle
option is now consistent withRadar
, 0 is at top and value is in degrees. Default is changed from-½π
to0
.scales.[x/y]Axes
arrays were removed. Scales are now configured directly tooptions.scales
object with the object key being the scale Id.scales.[x/y]Axes.barPercentage
was moved to dataset optionbarPercentage
scales.[x/y]Axes.barThickness
was moved to dataset optionbarThickness
scales.[x/y]Axes.categoryPercentage
was moved to dataset optioncategoryPercentage
scales.[x/y]Axes.maxBarThickness
was moved to dataset optionmaxBarThickness
scales.[x/y]Axes.minBarLength
was moved to dataset optionminBarLength
scales.[x/y]Axes.ticks.beginAtZero
was renamed toscales[id].beginAtZero
scales.[x/y]Axes.ticks.max
was renamed toscales[id].max
scales.[x/y]Axes.ticks.min
was renamed toscales[id].min
scales.[x/y]Axes.ticks.reverse
was renamed toscales[id].reverse
scales.[x/y]Axes.ticks.suggestedMax
was renamed toscales[id].suggestedMax
scales.[x/y]Axes.ticks.suggestedMin
was renamed toscales[id].suggestedMin
scales.[x/y]Axes.time.format
was renamed toscales[id].time.parser
scales.[x/y]Axes.time.max
was renamed toscales[id].max
scales.[x/y]Axes.time.min
was renamed toscales[id].min
- The dataset option
tension
was renamed tolineTension
- To override the platform class used in a chart instance, pass
platform: PlatformClass
in 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.animationDuration
is now configured inanimation.active.duration
responsiveAnimationDuration
is now configured inanimation.resize.duration
Developer migration
Removed
Chart.chart.chart
Chart.Controller
Chart.prototype.generateLegend
Chart.types
Chart.Tooltip
is now provided by the tooltip plugin. The positioners can be accessed fromtooltipPlugin.positioners
DatasetController.addElementAndReset
DatasetController.createMetaData
DatasetController.createMetaDataset
Element.getArea
Element.height
Element.initialize
Element.inLabelRange
helpers.addEvent
helpers.aliasPixel
helpers.configMerge
helpers.indexOf
helpers.lineTo
helpers.longestText
was moved to thehelpers.canvas
namespace and made privatehelpers.max
helpers.measureText
was moved to thehelpers.canvas
namespace and made privatehelpers.min
helpers.nextItem
helpers.numberOfLabelLines
helpers.previousItem
helpers.removeEvent
helpers.roundedRect
helpers.scaleMerge
helpers.where
ILayoutItem.minSize
IPlugin.afterScaleUpdate
. UseafterLayout
insteadLine.calculatePointY
LogarithmicScale.minNotZero
Scale.getRightValue
Scale.handleDirectionalChanges
is now privateScale.longestLabelWidth
Scale.longestTextCache
is now privateScale.mergeTicksOptions
Scale.ticksAsNumbers
Scale.tickValues
is now private- The tooltip item's
x
andy
attributes were removed. UsedatasetIndex
andindex
to get the element and any corresponding data from it
Removal of private APIs
Chart.data.datasets[datasetIndex]._meta
Element._ctx
Element._model
Element._view
LogarithmicScale._valueOffset
TimeScale._getPixelForOffset
TimeScale.getLabelWidth
Tooltip._lastActive
Renamed
Chart.Animation.animationObject
was renamed toChart.Animation
Chart.Animation.chartInstance
was renamed toChart.Animation.chart
helpers._decimalPlaces
was renamed tohelpers.math._decimalPlaces
helpers.almostEquals
was renamed tohelpers.math.almostEquals
helpers.almostWhole
was renamed tohelpers.math.almostWhole
helpers.callCallback
was renamed tohelpers.callback
helpers.clear
was renamed tohelpers.canvas.clear
helpers.distanceBetweenPoints
was renamed tohelpers.math.distanceBetweenPoints
helpers.drawRoundedRectangle
was renamed tohelpers.canvas.roundedRect
helpers.getAngleFromPoint
was renamed tohelpers.math.getAngleFromPoint
helpers.getMaximumHeight
was renamed tohelpers.dom.getMaximumHeight
helpers.getMaximumWidth
was renamed tohelpers.dom.getMaximumWidth
helpers.getRelativePosition
was renamed tohelpers.dom.getRelativePosition
helpers.getStyle
was renamed tohelpers.dom.getStyle
helpers.getValueAtIndexOrDefault
was renamed tohelpers.valueAtIndexOrDefault
helpers.getValueOrDefault
was renamed tohelpers.valueOrDefault
helpers.easingEffects
was renamed tohelpers.easing.effects
helpers.log10
was renamed tohelpers.math.log10
helpers.isNumber
was renamed tohelpers.math.isNumber
helpers.sign
was renamed tohelpers.math.sign
helpers.retinaScale
was renamed tohelpers.dom.retinaScale
helpers.splineCurve
was renamed tohelpers.curve.splineCurve
helpers.splineCurveMonotone
was renamed tohelpers.curve.splineCurveMonotone
helpers.toDegrees
was renamed tohelpers.math.toDegrees
helpers.toRadians
was renamed tohelpers.math.toRadians
Scale.calculateTickRotation
was renamed toScale.calculateLabelRotation
TimeScale.getLabelCapacity
was renamed toTimeScale._getLabelCapacity
TimeScale.getPixelForOffset
was renamed toTimeScale._getPixelForOffset
TimeScale.tickFormatFunction
was renamed toTimeScale._tickFormatFunction
Tooltip.options.legendColorBackgroupd
was renamed toTooltip.options.multiKeyBackground
Renamed private APIs
helpers._alignPixel
was renamed tohelpers.canvas._alignPixel
helpers._decimalPlaces
was renamed tohelpers.math._decimalPlaces
chart.initialize
was renamed tochart._initialize
(labeled as private but not named as such)
Changed
Scales
Scale.getLabelForIndex
was replaced byscale.getLabelForValue
Scale.getPixelForValue
now has only one parameter. For theTimeScale
that parameter must be millis since the epoch
Ticks
Scale.afterBuildTicks
now has no parameters like the other callbacksScale.buildTicks
is now expected to return tick objectsScale.convertTicksToLabels
was renamed togenerateTickLabels
. It is now expected to set the label property on the ticks given as inputScale.ticks
now contains objects instead of strings- When the
autoSkip
option is enabled,Scale.ticks
now contains only the non-skipped ticks instead of all ticks.
Time Scale
getValueForPixel
now returns milliseconds since the epoch
Controllers
Core Controller
- The first parameter to
updateHoverStyle
is now an array of objects containing theelement
,datasetIndex
, andindex
Dataset Controllers
updateElement
was replaced withupdateElements
now taking the elements to update, thestart
index, andmode
setHoverStyle
andremoveHoverStyle
now additionally take thedatasetIndex
andindex
Interactions
- Interaction mode methods now return an array of objects containing the
element
,datasetIndex
, andindex
Layout
ILayoutItem.update
no longer has a return value
Helpers
Canvas Helper
- The second parameter to
drawPoint
is now the full options object, sostyle
,rotation
, andradius
are no longer passed explicitly
Platform
Chart.platform
is 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.platforms
is an object that contains two usable platform classes,BasicPlatform
andDomPlatform
. It also containsBasePlatform
, a class that all platforms must extend from.- If the canvas passed in is an instance of
OffscreenCanvas
, theBasicPlatform
is automatically used.