我收到了客户的请求,要求提供使用折线图的项目燃尽图。问题是他们希望 x 轴上的日期以特定方式格式化 mmm dd-dd/yy(例如 Nov 18-24/12),其中 18-24 是一周(18 日到 24 日)。是否可以在 D3 中创建自定义日期格式,如果不能,实现此目的的最佳方法是什么?
最佳答案
是的,您可以创建自定义日期格式。
var xAxis = d3.svg.axis()
.scale(x)
.tickFormat(customDateFormat);
function customDateFormat(date) {
// figure out what week the current date is in
// and return the appropriate string
}
如果您想要更高级,您可以像 d3.js 实现内置格式化程序一样实现完整的格式化程序。请参阅http://bl.ocks.org/4149176举个例子。
关于javascript - d3自定义日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13726449/