If you are using a date in the form of milliseconds does it need to be converted to a string in order for the Date object to recognize it?
"values":[ {x:1390636800000 , y:12} ,
{ x:1390640400000 , y:17} ,
{ x:1390644000000 , y:17},
{ x:1390647600000 , y:15},
{ x:1390651200000 , y:8} ]
如果是这样,我将如何转换它以便它可以被正确使用
chart.xAxis
.axisLabel("Time (s)")
.tickFormat(function(d){return d3.time.format('%I%p')(new Date(d))});
并且它没有吐出 December/31/1969 日期?我尝试对整个对象进行字符串化,但这不起作用。有什么建议么?感谢您的帮助,如果这是一个愚蠢的问题,抱歉
(编辑)这是我正在使用的工作代码,无法正确显示时间
var chart;
nv.addGraph(function() {
chart = nv.models.lineChart()
.options({
margin: {left: 100, bottom: 100},
x: function(d,i) { return i},
showXAxis: true,
showYAxis: true,
transitionDuration: 250
})
;
chart.xAxis
.axisLabel("Time (s)")
.tickFormat(function(d){return d3.time.format('%m/%d/%y')(new Date(d))});
chart.yAxis
.tickFormat(d3.format('d'))
;
d3.select('#chart1 svg')
.datum(data1())
.call(chart);
nv.utils.windowResize(chart.update);
chart.dispatch.on('stateChange', function(e) { nv.log('New State:', JSON.stringify(e)); });
return chart;
});
function data1() {
return [
{
"values":[ {x:1390636800000 , y:12} , { x:1390640400000 , y:17} , { x:1390644000000 , y:17}, { x:1390647600000 , y:15}, { x:1390651200000 , y:8} ],
"key": "First Dude "
},
{
"values": [ { x:1390636800000 , y:16} , { x:1390640400000 , y:16} , { x:1390644000000 , y:16}, { x:1390647600000 , y:12}, { x:1390651200000 , y:5}],
"key": "Second Dude "
},
{
"values": [ { x:1390636800000 , y:5} , { x:1390640400000 , y:5} , { x:1390644000000 , y:5}, { x:1390647600000 , y:3}, { x:1390651200000 , y:1}],
"key": "Third Dude "
}
,
{
"values": [ { x:1390636800000 , y:8} , { x:1390640400000 , y:18} , { x:1390644000000 , y:18}, { x:1390647600000 , y:9}, { x:1390651200000 , y:7}],
"key": "Fourth Dude "
}
];
}