我正在使用nvd3.js实现图形。 我的代码是这样的:x轴缺少日期
nv.addGraph(function() {
charts = nv.models.lineChart();
var chart = charts.margin({
top: 100,
right: 20,
bottom: 50,
left: 45
}).showLegend(true).tooltipContent(function (key, y, e, graph) {
return '<h3>' + key + '</h3>' + '<p>' + e + '% at ' + y + '</p>'
});
chart.xAxis.tickFormat(function (d) {
return d3.time.format('%x')(new Date(d))
});
chart.yAxis
.tickFormat(d3.format(',d'));
chart.forceY([0,20]);
d3.select('#lineChart svg')
.datum(dateArr)
.transition(500).duration(500)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
哪里dateArr
是[{"key":"182398","values":[{"x":"1375295400000","y":"2"},{"x":"1374517800000","y":"2"},{"x":"1374604200000","y":"12"},{"x":"1374431400000", "y":"1"},{"x":"1375122600000","y":"4"},{"x":"1375209000000","y":"19"}]},{"key":"185271","values":[{"x":"1375295400000","y":"0"},{ "x":"1374517800000","y":"1"},{"x":"1374604200000","y":"2"},{"x":"1374431400000","y":"0"},{"x":"1375122600000","y":"0"},{"x":"1375209000000","y":"0"}]}];
按照数据,对于185271
有两种数据的一个是1上23-07-2013,另一个是2上24-07- 2013。但是,如果您看到附加的图像,则在x轴中显示的日期存在问题。即使24-07-2013不在x轴上。即使你可以看到第一次约会的重复。 请让我知道问题出在哪里以及我修改了什么。
在此先感谢。
把你的代码放在[JSFiddle](http://jsfiddle.net/)上,这样我们可以看看 – shabeer90
我不能在jsfiddle中运行,虽然我更新了jsfiddle中的代码 http:// jsfiddle。 net/srimanta/saXV5/8/ – Mausumi