问题
I use c3 to create simple graphs. I want to get datas from a Json file and fill it to create my Line-Graph.
My Y Values should be ("Labels") and my X Values should be ("Datas"). So this is, how my Code looks like:
var chart = c3.generate({
bindto: '#chart',
data: {
xFormat: '%Y-%m-%dT%H:%M:%S',
json: {
times:datas,
data: labels
}
}
});
My "datas" (Array) are:
"2014-01-01T10:10:10"
"2014-02-01T10:10:10"
"2014-03-01T10:10:10"
"2014-04-01T10:10:10"
"2014-05-01T10:10:10"
...
And my labels :
1234.433
2234.431
1231.546
8965.354
....
How can I set now, my datas into the X-Axis and labels into Y?
回答1:
In order to create a date histogram, you have to define your x-axis as a timeseries.
The result looks like this:
var chart = c3.generate({
data: {
x: "time",
json: {
time: datas,
data: labels
}
},
axis:{
x:{
type: "timeseries",
tick:{
format:"%Y-%m-%dT%H:%M:%S"
}
}
}
});
来源:https://stackoverflow.com/questions/40918278/c3-js-how-to-set-json-datas-in-x-y-axis