我尝试通过 ajax 函数获取序列和数据来检索数据,在 Document.ready 中:
function requestData() {
$.ajax({
type: 'POST',
dataType: 'json',
url: xxxxx,
async: false,
// you can use an object here
success: function(data) {
$("html").css('cursor','auto');
//remove previous data
while(chart.series.length > 0)
chart.series[0].remove(true);
$.each(data, function(val, text) {
counter = 0;
$.each(text, function() {
if (counter==0) {
datoscol= "[" + this + "]";
}
else{
datoscol= datoscol + "," + "[" + this + "]";
}
counter=1
});
datoscol = "["+datoscol + "]";
alert (datoscol);
chart.addSeries({
name: val,
data: datoscol
});
});
chart.redraw();
},
cache: false
});
}
我还在 document.ready 中初始化 Highcharts:
chart = new Highcharts.Chart({
chart: {
renderTo: 'container2',
type: 'line',
pointInterval: 30*24 * 3600 * 1000,
events: {
load: function(){
chart = this;
requestData();
}
}
},
title: {
text: 'Facturación clínica'
},
credits: {
enabled: false
},
xAxis: {
type: 'datetime',
maxZoom: 14 * 24 * 3600000, // fourteen days
title: {
text: null
}
},
yAxis: {
title: {
text: 'Facturación (€)'
}
},
tooltip: {
formatter: function() {
var s;
if (this.point.name) { // the pie chart
s = ''+
this.point.name +': '+ this.y +' fruits';
} else {
s = ''+
this.y + " Euros";
}
return s;
}
},
labels: {
items: [{
html: 'Facturación clínica',
style: {
left: '40px',
top: '8px',
color: 'black'
}
}]
}
});
我从服务器获得的数据类似于: {"Employee1":[["1356908400000","10.00"],["1359586800000","11.00"], ["1362006000000","12.00"],["1364684400000" ,"13.45"]],"Employee2":[["1356908400000","10.00"],["1359586800000","11.00"],["1362006000000","12.00"],["1364684400000","13.45" ]]}
因此,当我将系列添加到 highcharts 时,值是,例如:chart.addSeries({ name: val, --------->Employee1 data: datoscol ------->[[" 1356908400000","10.00"],["1359586800000","11.00"], ["1362006000000","12.00"],["1364684400000","13.45"]]
我通过萤火虫控制台没有收到任何错误,但除了轴和图例之外,什么也没有出现。我得到了所有系列的名称,但没有关于数据,没有标记,没有线条。