Why cant I make my Highcharts drill down work when I change json data from hardcoded javscript below to parse from a php mysql ?
Codes are as below
json source hardcoded in java script that works
drilldowns = {
name: 'Animals',
data: [
['Cows', 2],
['Sheep', 3]
]
},
When I call json from the following php code it doesn't
<?php
$ret = array();
$mtbf = array();
$mtbf['name'] = "Animals";
$mtbf['data'] = array(
array( 'Cows', 2),
array( 'Sheep',3) );
array_push($ret,$mtbf);
echo json_encode($ret);
?>
I combined both source of json for easy trouble shooting and below works
$.get("/drilldown.php?name=" +e.point.name, function(data) {
drilldowns = {
name: 'Animals',
data: [
['Cows', 2],
['Sheep', 3]
]
},
series = drilldowns;
alert(series);
chart.addSeriesAsDrilldown(e.point, series);
});
But if I change to the series from drilldowns to data it doesn't work
series = data;
Any help will be much appreciated
As per comments console log for data as follows
[{"name":"Animals","data":[["Cows",2],["Sheep",3]]}]
console log for drilldowns
Object {name: "Animals", data: Array(2)}
I managed to solve the problem by adding the header as well minor tweak on the array assignment and the drilldown worked.
<?php
header("Content-Type: application/json");
$mtbf = array();
$mtbf['name'] = "Animals";
$mtbf['data'] = array(array( 'Cows', 2),array( 'Sheep',3));
//var_dump($mtbf);
//array_push($ret,$mtbf);
echo json_encode($mtbf);
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.