I’m trying to create some Highstock charts (Highcharts) using sampled data but all I get when I run it its a blank page.
This is my php code:
<?php
header("Content-type: text/json");
$horas_muertas = array(array(1296518400000,4),array(1296604800000,2),array(1296691200000,3),array(1296777600000,3));
$horas_trabajadas = array(array(1296518400000,2),array(1296604800000,3),array(1296691200000,4),array(1296777600000,5));
$datos = array(json_encode($horas_muertas),json_encode($horas_trabajadas));
$datosj = json_encode($datos);
echo $datosj[0];
?>
As you can see I tried accesing the first location of the JSON, which returned this so I’m sure something’s wrong there:
[
But when I use this code for the chart(I removed non-relevant code):
function requestData() {
$.ajax({
url: 'data.php',
datatype: 'json',
success: function(data) {
//alert(data);
chart.series[0].setData(data[0]);
chart.series[1].setData(data[1]);
},
cache: false
});
}
$(function() {
var chart = new Highcharts.StockChart({
chart: {
renderTo: 'container',
type: 'column',
events: {
load: requestData
}
},
series: [{
name: 'Horas Prendidas',
data: []},
{
name: 'Horas Trabajadas',
data: []}]
});
});
All I get is a blank page,when I at least should get a chart without any data on it, any ideas on how to solve this? Help is much appreciated
Use
chart.series[0].addPoint(data[0]);instead ofchart.series[0].setData(data[0]);