webpack - echarts - 覆盖时间刻度组件
问题描述
我希望能够修改/覆盖比例级别: https ://github.com/apache/incubator-echarts/blob/0711cdfb0f5d8809d106a34e2e16daad991cb9e1/src/scale/Time.js#L211
具体来说,我想在 Time.js 中将 'year' 更改为 'yyyy',或者能够覆盖 format.js 中的 formatTime 函数。
有没有办法做到这一点?我使用 webpack 构建库,我可以这样覆盖组件吗?
解决方案
您可以覆盖 formatTime 函数。在图表初始化之前运行此代码。
const echartsFormatTime = echarts.format.formatTime;
echarts.format.formatTime = function formatTime(tpl, value, isUTC) {
switch (tpl) {
case 'dd/MM/yyyy':
break;
case 'year':
tpl = 'yyyy';
break;
case 'MM-dd\nyyyy':
tpl = 'dd/MM/yyyy';
break;
default:
tpl = 'MM/yyyy';
}
return echartsFormatTime(tpl, value, isUTC);
}