I am newbie to d3.js, as well as to c3.js. I want dynamic timestamp in c3.js as shown in this d3.js example. It should change time format according to the range of time.
I am following c3js.org's time series example. But not able to get dynamic range.
The code is as follows.
Update 1
var date1=new Date(1397657484*1000);
var date2=new Date(1397657514*1000);
var date3=new Date(1397657554*1000);
var date4=new Date(1397657594*1000);
var date5=new Date(1397657641*1000);
var date6=new Date(1398323901*1000);
var seconds = (date6.getTime() - date1.getTime())/1000;
var xaxisformat;
if (seconds < 86400)
{
xaxisformat = '%I:%M:%S';
}
else {
xaxisformat = '%Y-%m-%d %I:%M';
}
var format=d3.time.format(xaxisformat); //I am converting after if loop since we are calculating seconds using javascript.
date1=format(date1); //I think this formatting required to pass d3.time to c3js
date2=format(date2);
date3=format(date3);
date4=format(date4);
date5=format(date5);
date6=format(date6);
var chart = c3.generate({
data: {
x: 'x',
columns: [
['x',date1, date2, date3, date4, date5, date6],
['data1', 30, 200, 100, 400, 150, 250],
['data2', 130, 340, 200, 500, 250, 350]
]
},
axis: {
x: {
type: 'timeseries',
tick: {
format: xaxisformat
}
}
}
});
This might be silly question, but I am newbie to this area.