Chart.js 时刻语言环境时刻、语言、环境、Chart

2023-09-07 11:47:21 作者:戎马

我正在构建一个 Angular 2 应用程序并使用 Chart.js 2.0 来显示时间"数据.不幸的是,我无法更改 moment.js 的语言环境.

I'm building an Angular 2 app and use Chart.js 2.0 to display 'time' data. Unfortunately I am not able to change the locale of moment.js.

我 npm 安装了 moment 并使用 SystemJS 导入 moment.js 和 pl.js,但 Chart.js 抱怨必须在 Chart.js 之前加载 moment.js(不知道如何实现,在每个源文件中,moment 都是在 chartjs 之前声明).

I npm installed moment and import moment.js and pl.js using SystemJS, but Chart.js complains that moment.js has to be loaded before Chart.js (not sure how to accomplish that, in every source file moment is declared before chartjs).

然后我尝试了 Chart.bundle.min.js(包括时刻),它可以工作,但只能用英语.我无法将语言环境更改为pl".

Then I tried the Chart.bundle.min.js (with moment included), which works but only in english. I am not able to change the locale to 'pl'.

以下行对 Chart.bundle.min.js 无效,日期仍以英文显示.

The following line has no effect with Chart.bundle.min.js and dates are still displayed in english.

moment.locale('pl');

Chart.js 是否有自己的函数来更改语言环境?文档没有指定任何关于帽子的内容.

Does Chart.js have an own function to change locale? The docs don't specify anything about hat.

推荐答案

Moment 的语言环境必须在 before 图表加载之前设置,否则必须使用 update() 更新图表.https://github.com/chartjs/Chart.js/issues/3108

Moment's locale must be set before the chart load else the chart must be updated with update(). https://github.com/chartjs/Chart.js/issues/3108

 
精彩推荐