I am following http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/drilldown/async/ Link for making Drilldown chart.
Example for you: http://jsfiddle.net/S3j35/
Use e.point.name
to determine which point is clicked and which data you need from server. When AJAX comes, just add series with new data:
drilldown: function (e) {
if (!e.seriesOptions) {
// e.point.name is info which bar was clicked
chart.showLoading('Simulating Ajax ...');
$.get("path/to/place.html?name=" + e.point.name, function(data) {
/***
where data is this format:
data = {
name: 'Cars',
data: [
['Toyota', 1],
['Volkswagen', 2],
['Opel', 5]
]
}
***/
chart.hideLoading();
chart.addSeriesAsDrilldown(e.point, data);
});
}
}
Below is the working code with ajax for drilldown levels:
<script type="text/javascript">
// Create the chart
Highcharts.chart('container', {
chart: {
type: 'column',
events: {
drilldown: function (e) {
if (!e.seriesOptions) {
var chart = this;
//calling ajax to load the drill down levels
chart.showLoading('Simulating Ajax ...');
$.get("ajax_response.php?name=" + e.point.name, function(data) {
chart.hideLoading();
chart.addSeriesAsDrilldown(e.point, jQuery.parseJSON(data));
});
}
}
}
},
title: {
text: 'Async drilldown'
},
xAxis: {
type: 'category'
},
legend: {
enabled: false
},
plotOptions: {
series: {
borderWidth: 0,
dataLabels: {
enabled: true
}
}
},
series: [{
name: 'Things',
colorByPoint: true,
data: [{
name: 'Animals',
y: 5,
drilldown: true
}, {
name: 'Fruits',
y: 2,
drilldown: true
}, {
name: 'Cars',
y: 4,
drilldown: true
}]
}],
drilldown: {
series: []
}
});
</script>
<!-- language: lang-html -->
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/drilldown.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<!-- end snippet -->
Create ajax_response.php with below codes:
<?php
if($_REQUEST['name'] == "Cars") {
$response = array('name' => 'Cars', 'data'=>array(array('Toyota', 1), array('Volkswagen', 2), array('Opel', 5)));
}else if($_REQUEST['name'] == "Fruits"){
$response = array('name' => 'Fruits', 'data'=>array(array('Apples', 5), array('Oranges', 7), array('Bananas', 2)));
}else if($_REQUEST['name'] == "Animals"){
$response = array('name' => 'Animals', 'data'=>array(array('Cows', 2), array('Sheep', 3)));
}
echo json_encode($response);
?>