NVD3.js | php | unix time stamp not working
-
26-12-2019 - |
Question
For some reason the timestamps i am using are not translating to the graph correctly. the graph says they are 01/16/1970 [ time stamp: 1389429242]. I am using strtotime (php function) to generate the time stamps. How do i generate the correct time stamp for this to work, using php?
Code:
<script>
nv.addGraph(function() {
var chart = nv.models.lineWithFocusChart();
chart.xAxis
.tickFormat(function(d) { return d3.time.format('%x')(new Date(d)) });
chart.x2Axis
.tickFormat(function(d) { return d3.time.format('%x')(new Date(d)) });
chart.yAxis
.tickFormat(d3.format(',f'));
chart.y2Axis
.tickFormat(d3.format(',f'));
d3.select('#chart svg')
.datum(
[
{
key : 'Current' ,
color : '#2ca02c',
values : [
{ x: 1389429242 , y:15 },
...
]
},
{
key : 'Backlog' ,
color : '#ff7f0e',
values : [
{ x: 1389429242 , y:50 },
...
]
}
]
)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
</script>
Solution
So apparently, JS time stamps are in milliseconds. So i had to multiply my php time stamp my 1000 and it works.
SOLVED
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow