2013-08-06 145 views
0

我正在使用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轴上。即使你可以看到第一次约会的重复。 请让我知道问题出在哪里以及我修改了什么。 enter image description here

在此先感谢。

+0

把你的代码放在[JSFiddle](http://jsfiddle.net/)上,这样我们可以看看 – shabeer90

+0

我不能在jsfiddle中运行,虽然我更新了jsfiddle中的代码 http:// jsfiddle。 net/srimanta/saXV5/8/ – Mausumi

回答

0

您的X TimeStamp是一个字符串,它必须是一个Integer,因此在工具提示中显示NaN的原因是删除了双引号。

+0

很好。非常感谢。 – Mausumi

+0

我遇到了另一个问题,如果数据非常少,则x轴(日期)与多个相同日期一起潜水。例如我只有2日期2013年7月23日和24-07-2013,然后我有4个23-07-2013列x轴。我只需要一个在X轴23-07-2013。可能吗? – Mausumi

+0

再次查看你传递的数据,确保你没有重复任何日期。 – shabeer90