I am having an issue with the labels assigned to the values of my graph.
The graph is a timeseries. I add values using the \'columns\' property of c3js.
I
I also faced the problem.Here is how I have resolved. Use the x-axis as category and not timeseries, and manipulate the corresponding tick format to look as if it is timeseris.
I have simplified the prob to make it generic.
Problem (irregular spacing):
var chart = c3.generate({
data: {
x: 'xtime',
xFormat: '%Y-%m-%d-%H-%M-%S',
columns: [
['xtime', '2015-05-20-05-10-13', '2015-05-20-05-11-13', '2015-05-21-06-10-13'],
['value', 30, 50, 20]
]
},
size: {
height: 300,
width: 600
},
axis: {
x: {
type: 'timeseries',
// type: 'category',
tick: {
// format: function(x) {
// var dateSubs = this.api.categories()[x].split('-'),
// newDate = new Date(dateSubs[0], dateSubs[1], dateSubs[2], dateSubs[3], dateSubs[4], dateSubs[5], 0);
//
// return newDate.toLocaleString();
// }
format: '%e-%b-%Y %H:%M'
}
}
}
});
Solution :
var chart = c3.generate({
data: {
x: 'xtime',
xFormat: '%Y-%m-%d-%H-%M-%S',
columns: [
['xtime', '2015-05-20-05-10-13', '2015-05-20-05-11-13', '2015-05-21-06-10-13'],
['value', 30, 50, 20]
]
},
size: {
height: 300,
width: 600
},
axis: {
x: {
// type: 'timeseries',
type: 'category',
tick: {
format: function(x) {
var dateSubs = this.api.categories()[x].split('-'),
newDate = new Date(dateSubs[0], dateSubs[1], dateSubs[2], dateSubs[3], dateSubs[4], dateSubs[5], 0);
return newDate.toLocaleString();
}
// format: '%e-%b-%Y %H:%M'
}
}
}
});