I'm trying to plot D3 timeseries by referring : http://mcaule.github.io/d3-timeseries/
which takes Date in this format : 'new Date('2013-01-01')
Now, I have following array:
var data =[{
"time": "2017-06-23T23:37:20-07:00",
"value": 25.189767114257663
},
{
"time": "2017-06-23T23:37:30-07:00",
"value": 24.637318860009692
},
{
"time": "2017-06-23T23:37:40-07:00",
"value": 24.896462306379043
},
{
"time": "2017-06-23T23:37:50-07:00",
"value": 24.348000192323468
}]
I need to give this array as input to the d3 timeseries function. But I'm unable to plot anything as above time is not a Date object. How do I append or convert that time string to date object. Because I absolutely need to have that new Date thing otherwise that function is not at all executing.
I tried to convert time into date object using:
data.map(function(ele) {
ele.time = new Date(ele.time);
});
So, this thing appended Zone to all the times. When I tried to give this array as input to d3 function, it doesn't work.
data, convert all time string to date object, and use the result new data object as the input to d3.data.forEach(item => item.time = new Date(item.time))will give you Date objects in the time propertyforEachinstead ofmap...it doesn't workis an often used phrase on stack overflow that is redundant (why else would you be asking a question) and meaningless by itself - do you get errors in the (developer tools) console? what do you observe? how does it differ from what you expect?