Reputation: 131
I am developing from the c3.js using reusable charts in d3.js,but unable to get the data from the array of objects,i tried for the given format of the code.
var chart=c3.generate({
data:{
json:[
{"key":[2000],"value":100},{"key":[2001],"value":200},{"key":[2003],"value":300},{"key":[2004],"value":400},{"key":[2005],"value":500},{"key":[2006],"value":600},{"key":[2007],"value":700}
],
keys:{x:'key[0]',
value:'value',
}
},
axis: {
x: {
type: "category"
}
}
})
Upvotes: 4
Views: 5130
Reputation: 1
I believe this what you are going for:
var chart = c3.generate({
data:{
json:[
{"key":2000,"value":100},{"key":2001,"value":200},
{"key":2003,"value":300},{"key":2004,"value":400},
{"key":2005,"value":500},{"key":2006,"value":600},
{"key":2007,"value":700}
],
keys:{
x: "key",
value:['value']
}
},
axis: {
x: {
type: "category"
}
}
});
I'm not sure why you would have the key for a data point be an array (perhaps you want to swap the keys and values?), but here is a basic key, value line graph, which is what I think you are going for.
checkout out this fiddle adapted from Sikandar Tamboli's answer
Upvotes: 0
Reputation: 59
chart.data('value')[0].values[0].value
c3 documentation here
check out this fiddle
Upvotes: 5