The data structure returned by my API is as follows. However, I need to reformat this structure for use in C3.js.
{
"data":{
"test7":[
{
"Date":"2016-04-26 00:00:00",
"aId":7,
"Amount":436464,
"Piece":37
},
{
"Date":"2016-04-26 01:00:00",
"aId":7,
"Amount":546546,
"Piece":37
},
{
"Date":"2016-04-26 02:00:00",
"aId":7,
"Amount":5461,
"Piece":37
}
],
"test4":[
{
"Date":"2016-04-26 00:00:00",
"aId":4,
"Amount":4564,
"Piece":60
},
{
"Date":"2016-04-26 01:00:00",
"aId":4,
"Amount":4756,
"Piece":60
},
{
"Date":"2016-04-26 02:00:00",
"aId":4,
"Amount":2355,
"Piece":60
}
],
"test5":[
{
"Date":"2016-04-26 00:00:00",
"aId":5,
"Amount":879,
"Piece":112
},
{
"Date":"2016-04-26 01:00:00",
"aId":5,
"Amount":1244,
"Piece":112
},
{
"Date":"2016-04-26 02:00:00",
"aId":5,
"Amount":982,
"Piece":112
}
]
}
This is the syntax of my C3.js chart. How can I transform the above data into the required column structure for C3.js?
var chart = c3.generate({
bindto: '#area-hour',
data: {
x: 'Date',
xFormat: '%Y-%m-%dT%H:%M:%S',
columns: [
['Date', '2016-04-26T00:00:00', '2016-04-26T01:00:00', '2016-04-26T02:00:00'],
['test7', 13371, 103871, 103371],
['test4', 21654, 2544, 1694],
['test5', 6185, 3185, 3785]
],
},
grid: {
y: {
show: true,
}
},
axis: {
x: {
type: 'timeseries',
tick: {
culling: false,
format : "%Y-%m-%d " + "\n\r" + "%H:%M:%S"
}
}
}
});