通过遍历json数据来构建剑道图的系列? [英] Building the series of a kendo chart by looping through the json data?
问题描述
我在弄清楚如何解决此问题时遇到了一些困难.基本上,我返回了一些如下所示的JSON:
I am having some difficulty figuring out how to solve this problem. Basically I have some JSON returned that looks like this:
{
"pie": {
"slice": [
{
"-ch": "1",
"-val": "0.0797435897435897"
},
{
"-ch": "2",
"-val": "0.00743589743589744"
},
{
"-ch": "3",
"-val": "0.247435897435897"
},
{
"-ch": "4",
"-val": "0.497179487179487"
},
{
"-ch": "5",
"-val": "0.168205128205128"
}
]
}
}
我从控制器到javascript都得到了这些数据.但是,我想将数据绑定到饼图.唯一的问题是,我将拥有数量不等的渠道.在此示例中,我有5个频道.我的JavaScript饼形图如下所示:
I am getting this data from the controller to the javascript just fine. However, I want to bind the data to a pie chart. The only issue is that, I will have varying amounts of channels. In this example, I have 5 channels. My pie chart in javascript looks like this:
$("#chartDiv").kendoChart({
title: {
position: "bottom",
text: "Chart"
},
legend: {
visible: false
},
chartArea: {
background: "transparent"
},
seriesDefaults: {
type: "donut",
startAngle: 150
},
series: [
{
name: "Chart",
data: ???????How to get the data here????????
}],
tooltip: {
visible: true,
template: "#= category #: #= value #%"
}
});
}
});
我尝试在调用中构建循环,也尝试了字符串构建定义,但它似乎也不喜欢该解决方案(不过,我可能会错误地实现了该解决方案.)感谢您的帮助.>
I have tried building a loop within the call, I have also tried string building the definition but it doesn't seem to like that solution either(I might of implemented this incorrectly though.) Thanks ahead for your help.
推荐答案
我知道了.
设置数据:dataVariable并按以下方式定义dataVariable:
set data: dataVariable and define dataVariable like this:
for (var i = 0; i < json.Slices.length; i++) {
dataVariable.push({
category: json.Slices[i].Ch,
value: parseFloat(json.Slices[i].val)
});
};
这篇关于通过遍历json数据来构建剑道图的系列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!