是否可以从具有以下结构的远程数据源创建剑道 UI 数据可视化图表
"gender": [
{"male": 23421},
{"female": 24376},
{"unknown": 324}
],
而不是使用(来自文档中的示例)
<div id="chart"></div>
<script>
$("#chart").kendoChart({
categoryAxis: {
field: "year"
},
series: [
{ field: "value" }
],
dataSource: [
{ year: "2012", value: 1 },
{ year: "2013", value: 2 }
]
});
</script>
我想使用格式为
<div id="chart"></div>
<script>
$("#chart").kendoChart({
categoryAxis: {
field: "year"
},
series: [
{ field: "value" }
],
dataSource: [
{ "2012": 1 },
{ "2013": 2 }
]
});
</script>
嗯,这是Javascript中的一个直接转换。
convertDataSource = function(dataSource) {
for(i in dataSource) {
(y = {})[dataSource[i].year] = dataSource[i].value;
dataSource[i] = y;
}
return dataSource;
}
convertDataSource([ { year: "2012", value: 1 }, { year: "2013", value: 2 }])
// [ { "2012": 1, "2013": 2}