我正在使用NVD3和Flask,我在x轴上有日期. 
如您所见,x轴上的线与点不一致.我在x轴上打印出日,月,年和小时.我不明白为什么日期不是等间隔,即即使我的x轴数据是'小时'也不一样,所以这些行分开超过"24小时".我认为这是导致问题的原因.
(编辑)我的代码是:
nv.addGraph(function() {
var chart = nv.models.lineChart();
chart.xAxis
.tickFormat(function(d) { return d3.time.format('%d %b %Y')(new Date(parseInt(d))) }
);
chart.yAxis
.tickFormat(d3.format(',.02f'));
chart.tooltipContent(function(key, y, e, graph) {
var x = d3.time.format('%d %b %Y')(new Date(parseInt(graph.point.x)));
var y = String(graph.point.y);
var y = String(graph.point.y);
tooltip_str = '<center><b>'+key+'</b></center>' + y + ' on ' + x;
return tooltip_str;
});
chart.showLegend(true);
d3.select('#lineChart svg')
.datum(data_lineChart)
.transition().duration(500)
.attr('width', 1200)
.attr('height', 450)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
Run Code Online (Sandbox Code Playgroud)
小智 11
这里有一个更好的建议,如果没有声明时间刻度,则d3不会很好地缩放由日期表示的x轴.
chart.xAxis
.tickFormat(function(d) {
return d3.time.format('%d-%m-%y')(new Date(d))
});
chart.xScale(d3.time.scale()); //fixes misalignment of timescale with line graph
Run Code Online (Sandbox Code Playgroud)