Document.ready で、ajax 関数を使用してシリーズとデータを取得してデータを取得しようとしています。
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'
}
}]
}
});
サーバーから取得したデータは次のようなものです。 ,"13.45"]],"Employee2":[["1356908400000","10.00"],["1359586800000","11.00"],["1362006000000","12.00"],["1364684400000","13.45" ]]}
したがって、セリエをハイチャートに追加すると、値は次のようになります: chart.addSeries({ name: val, ---------->Employee1 data: datoscol ------->[[" 1356908400000","10.00"],["1359586800000","11.00"],["1362006000000","12.00"],["1364684400000","13.45"]]
firebug コンソールでエラーは発生しませんが、軸と凡例以外は何も表示されません。すべてのシリーズ名を取得しますが、データ、マーカー、線については何も取得しません。