[英]About C3.js chart data split
Since i am not familiar with C3.js library, i am bit confuse when i tried to split the Array data. 由于我不熟悉C3.js库,当我试图拆分数组数据时,我有点困惑。
For instant i have some array value from a json. 对于即时我有一些来自json的数组值。
var jsondata=[[123],[45],[56],[22]];
var jsondataName=[["apple"],["orange"],["banana"],["pear"]];
I tried to pass the first array jsondata into the chart but these values go into the same column which is not something i would like to see. 我试图将第一个数组jsondata传递到图表中,但这些值进入同一列,这不是我想看到的。
I want these array value become independent data and push the name into it 我希望这些数组值成为独立数据并将名称推入其中
Please see the demo i made : http://jsfiddle.net/q8h39/92/ 请参阅我制作的演示: http : //jsfiddle.net/q8h39/92/
And the result i want should looks like 我想要的结果应该是这样的
Update the json data format : 更新json数据格式:
"Name": apple,
"data": {
"value": 1434,
}
"Name": banana,
"data": {
"value": 342,
}
}
}
You can set the JSON object to data.json
and then set data.keys.value
to an array of values in that JSON: 您可以将JSON对象设置为
data.json
,然后将data.keys.value
设置为该JSON中的值数组:
var jsondata = [{
"Name": "apple",
"data": {
"value": 1434,
},
}, {
"Name": "banana",
"data": {
"value": 342,
}
}];
var chart = c3.generate({
data: {
json: jsondata,
keys: {
value: [
"name", "data.value"
]
},
type: "scatter"
//hide: true
}
});
http://jsfiddle.net/aendrew/mz9ccbrc/ http://jsfiddle.net/aendrew/mz9ccbrc/
nb, You need C3 v0.4.11 for this (the dot syntax for keys.value
was just added), and your JSON object needs to be an array (currently it's not valid). nb,你需要C3 v0.4.11(刚刚添加了
keys.value
的点语法),你的JSON对象需要是一个数组(目前它无效)。
If you want to convert the two arrays from your initial question to that format of JSON, try this: 如果要将两个数组从初始问题转换为JSON格式,请尝试以下操作:
d3.zip(jsondataName, jsondata)
.map((d) => Object({name: d[0][0], data: { value: d[1][0] } }));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.