来自 webservice 的数据是从 BindTrend 方法获取的,并在绑定到图表之前解析为 Json 对象: 我的代码如下:
var plot;
var itemdata = [];
var chart;
var data = [];
$(document).ready(function () {
$.ajax({
type: "POST",
url: "ChartBinder.asmx/BindTrend",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var newJ = $.parseJSON(msg.d);
DrawTrend(newJ);
},
error: function (msg) {
alert("Error");
}
});
})
function DrawTrend(plot) {
for (i = 0; i < plot.length; i++) {
var x = {}
x.id=plot[i].Name;
x.name = plot[i].Name;
x.data = [plot[i].Value];
itemdata.push(x);
}
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'line',
marginRight: 130,
marginBottom: 25
},
series: itemdata
});
}
请注意,当我对值进行硬编码时'x.data=[1,2,3....]'
,我可以获得图表。请帮忙。