0

So I have finally managed to get a chart generated, but the problem is that for some reason the data from JSON is not displayed - ie I get a blank chart.

In the chart options I simply have:

series : [{
    name: '2000',
    data: [],
}]

The AJAX call looks like this:

$.ajax({
    url : 'data.php',
    datatype : 'json',
    success : function (json) {
        options.series[0].data = json['data'];
        chart = new Highcharts.Chart(options);
    },
});
}

And the data.php output looks like this:

{"data":[-1.4,-1.4,-1.3,-1.3,-1.3,-1.3,-1.3,-1.2,-1.3,-1.2,-1.2,-1.2]}

Im becoming desperate as I tried everything and still get just a blank chart with no data.

6
  • are any errors showing up in your javascript console? What is your ajax call returning, is it resulting in 200 with the expected response from your php? Commented Oct 21, 2013 at 21:18
  • no there are no errors, I am just not sure wheather it is ok, if the final line of data.php is: echo json_encode($rows, JSON_NUMERIC_CHECK); and before that I have while($r = mysqli_fetch_array($x)){ $rows['data'][] = $r['Temp']; } Which loads the data, the actual "echo" produces: {"data":[-1.4,-1.4,-1.3,-1.3,-1.3,-1.3,-1.3,-1.2,-1.3,-1.2,-1.2,-1.2]} Commented Oct 21, 2013 at 21:20
  • why dont you just hardcode some of the data to series.data and see if you are getting a chart with some data Commented Oct 21, 2013 at 21:20
  • also try printing json, before you call options.series[0].data = json['data'] Commented Oct 21, 2013 at 21:22
  • I tried to delete the options.series..... line and instead I put some data into the data in the series and then I get a normal chart with the data points. Commented Oct 21, 2013 at 21:23

2 Answers 2

1

If you're using Internet Explorer, those extra commas will cause you problems.

series : [{
    name: '2000',
    data: []
}]

$.ajax({
    url : 'data.php',
    datatype : 'json',
    success : function (json) {
        options.series[0].data = json['data'];
        chart = new Highcharts.Chart(options);
    }
});
}
Sign up to request clarification or add additional context in comments.

Comments

0

Its likely that your json values are coming back as strings but highcharts is expecting numbers.

In your data.php try typing your variables before json_encoding them:

array_push($myArray, (float)$value);
return json_encode(myArray);

If your highcharts data looks like:

["-1.4","-1.4","-1.3","-1.3","-1.3","-1.3","-1.3","-1.2","-1.3","-1.2","-1.2","-1.2"]

It wont render, it needs to be straight number:

[-1.4,-1.4,-1.3,-1.3,-1.3,-1.3,-1.3,-1.2,-1.3,-1.2,-1.2,-1.2]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.