How to format date and time in Dygraphs legend according to user locale

a 夏天 提交于 2019-12-06 08:16:14

You've discovered the axisLabelFormatter option, which lets you control formatting of labels on the x-axis.

To control formatting of labels in the legend, you need to use valueFormatter

g = new Dygraph(div, data,
    axes: {
        x: {
            axisLabelFormatter: function (d, gran) {
                return d.toLocaleDateString();
            },
            valueFormatter: function (ms) {
                return new Date(ms).toLocaleDateString();
            }
        }
    }
});

See this fiddle for a fully-worked example. Is it odd that one formatter function takes a Date whereas the other takes millis since epoch? Yes. Unfortunately, it's an inconsistency we're stuck with.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!