# 4.x 迁移指南

¥4.x Migration Guide

Chart.js 4.0 引入了一些重大变化。我们尝试将重大更改的数量保持在最低限度。对于某些功能和错误修复,有必要打破向后兼容性,但我们的目标是仅在值得受益时才这样做。

¥Chart.js 4.0 introduces a number of breaking changes. We tried keeping the amount of breaking changes to a minimum. For some features and bug fixes it was necessary to break backwards compatibility, but we aimed to do so only when worth the benefit.

# 终端用户迁移

¥End user migration

# 图表

¥Charts

  • 图表不会覆盖默认的工具提示回调,因此所有图表类型都具有外观相同的工具提示。

    ¥Charts don't override the default tooltip callbacks, so all chart types have the same-looking tooltips.

  • 如果配置的比例以 x/y 开头,则默认比例覆盖已被删除。在你的配置中定义 xAxes 现在将创建第二个比例,而不是覆盖默认的 x 轴。

    ¥Default scale override has been removed if the configured scale starts with x/y. Defining xAxes in your config will now create a second scale instead of overriding the default x axis.

# 选项

¥Options

对传递给 Chart 构造函数的配置选项进行了一些更改。这些更改记录在下面。

¥A number of changes were made to the configuration options passed to the Chart constructor. Those changes are documented below.

# 具体变化

¥Specific changes

  • radialLinear grid indexable 和 scriptable 选项不再减少指定网格线的索引。

    ¥The radialLinear grid indexable and scriptable options don't decrease the index of the specified grid line anymore.

  • destroy 插件钩子已被删除并替换为 afterDestroy

    ¥The destroy plugin hook has been removed and replaced with afterDestroy.

  • 时间刻度上的滴答回调现在接收时间戳而不是格式化标签。

    ¥Ticks callback on time scale now receives timestamp instead of a formatted label.

  • scales[id].grid.drawBorder 已重命名为 scales[id].border.display

    ¥scales[id].grid.drawBorder has been renamed to scales[id].border.display.

  • scales[id].grid.borderWidth 已重命名为 scales[id].border.width

    ¥scales[id].grid.borderWidth has been renamed to scales[id].border.width.

  • scales[id].grid.borderColor 已重命名为 scales[id].border.color

    ¥scales[id].grid.borderColor has been renamed to scales[id].border.color.

  • scales[id].grid.borderDash 已重命名为 scales[id].border.dash

    ¥scales[id].grid.borderDash has been renamed to scales[id].border.dash.

  • scales[id].grid.borderDashOffset 已重命名为 scales[id].border.dashOffset

    ¥scales[id].grid.borderDashOffset has been renamed to scales[id].border.dashOffset.

  • 比例尺边界的 z 索引现在是可配置的,而不是比网格 z 索引高 1。

    ¥The z index for the border of a scale is now configurable instead of being 1 higher as the grid z index.

  • 如果最小值和最大值相同而不是 1,则线性刻度现在将最大值的 5% 添加和减去范围。

    ¥Linear scales now add and subtracts 5% of the max value to the range if the min and max are the same instead of 1.

  • 如果工具提示回调返回 undefined,则将使用默认回调。

    ¥If the tooltip callback returns undefined, then the default callback will be used.

  • maintainAspectRatio 尊重容器高度。

    ¥maintainAspectRatio respects container height.

  • 时间和时间序列尺度使用 ticks.stepSize 而不是 time.stepSize,后者已被删除。

    ¥Time and timeseries scales use ticks.stepSize instead of time.stepSize, which has been removed.

  • 如果确定的最大刻度小于 maxTicksLimit,则 maxTickslimit 将不会用于 autoSkip 中的刻度。

    ¥maxTickslimit won't be used for the ticks in autoSkip if the determined max ticks is less then the maxTicksLimit.

  • dist/chart.js 已被删除。

    ¥dist/chart.js has been removed.

  • dist/chart.min.js 已重命名为 dist/chart.umd.js

    ¥dist/chart.min.js has been renamed to dist/chart.umd.js.

  • dist/chart.esm.js 已重命名为 dist/chart.js

    ¥dist/chart.esm.js has been renamed to dist/chart.js.

# 类型变化

¥Type changes

  • ChartMeta 参数的顺序已从 <Element, DatasetElement, Type> 更改为 <Type, Element, DatasetElement>

    ¥The order of the ChartMeta parameters have been changed from <Element, DatasetElement, Type> to <Type, Element, DatasetElement>.

# 一般的

¥General