I try to get series and data through ajax Function to retrieve data, in 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
});
}
I also initialize Highcharts in document.ready:
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'
}
}]
}
});
Data I get from the server is something like: {"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"]]}
So when I add the serie to highcharts, the values are, for example: chart.addSeries({ name: val, --------->Employee1 data: datoscol ------->[["1356908400000","10.00"],["1359586800000","11.00"], ["1362006000000","12.00"],["1364684400000","13.45"]]
I get no error through firebug console but nothing appear, except the axis and legends. I get all the series names but nothing about the data, no markers, no lines.