echarts - 覆盖时间刻度组件

echarts - override time scale component

我希望能够修改/覆盖比例级别: 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);
    }