我想用StackedAreChart
使用nvd3.js
来显示网络流量。 我需要在X轴上显示每小时的勾号:00:00 01:00 02:00 ... 24:00。我怎么做?
reference the StackedAreaChart in this page如何在StackedAreChart中使xAxis每小时刻度(如0,1,2,...,23)使用nvd3.js?
nv.addGraph(function() {
var chart = nv.models.stackedAreaChart()
.x(function(d) { return d[0] })
.y(function(d) { return d[1] })
.clipEdge(true)
.useInteractiveGuideline(true)
;
chart.xAxis
.showMaxMin(false)
//.ticks(d3.time.hour,2) //I wrote this line,but is does not work
.tickFormat(function(d) { return d3.time.format('%H:%M')(new Date(d))
});
chart.yAxis.tickFormat(d3.format(',.2f'));
d3.select('#chart svg')
.datum(data)
.transition().duration(500).call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
我试过这个,但它不起作用: chart.xAxis.ticks(24)。 tickFormat(function(d){return d3.time.format('%H:%M')(new Date(d))}); – tao4yu
结果如何? – RenatoUtsch
结果没有改变 – tao4yu