[英]Chart using highcharts and Json asp.net MVC
This is the first time i try to use Json i can't solve this problem the controller 这是我第一次尝试使用Json,但控制器无法解决此问题
return this json 返回这个json
[
{"ID":1,"month":"september","sale":120},
{"ID":2,"month":"september","sale":122}
]
the chart needs data in this format 图表需要这种格式的数据
data: [
['Firefox', 45.0],
['IE', 26.8],
{
name: 'Chrome',
y: 12.8,
}]
how to get the data returned by the controller to the chart in the right format?? 如何以正确的格式获取控制器返回到图表的数据?
This solution don't work 该解决方案不起作用
var data=[];
var uri = 'api/chartapi';
/* $(function () {
$.getJSON(uri)
.done(function (json) {
$.each(data, function (name, score) { {
data.push({
name: name,
y: score
});
}
});
});
});
Maybe simply parse that format on js? 也许只是在js上解析该格式? Like this: http://jsfiddle.net/3bQne/992/ 像这样: http : //jsfiddle.net/3bQne/992/
var data = [],
json = [{
"ID": 1,
"month": "september",
"sale": 120
}, {
"ID": 2,
"month": "september",
"sale": 122
}];
for (var i = 0; i < json.length; i++) {
data.push({
name: json[i].month,
id: json[i].ID,
y: json[i].sale
});
}
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'pie'
},
series: [{
data: data
}]
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.