Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

High Chart Async drilldown

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.

I am not able to understand how can I set value for drilldowns = {} (dynamically from ajax call) and series = drilldowns[e.point.name];

drilldowns = {
                            'Animals': {
                                name: 'Animals',
                                data: [
                                    ['Cows', 2],
                                    ['Sheep', 3]
                                ]
                            },
                            'Fruits': {
                                name: 'Fruits',
                                data: [
                                    ['Apples', 5],
                                    ['Oranges', 7],
                                    ['Bananas', 2]
                                ]
                            },
                            'Cars': {
                                name: 'Cars',
                                data: [
                                    ['Toyota', 1],
                                    ['Volkswagen', 2],
                                    ['Opel', 5]
                                ]
                            }
                        }

I have tried to search .addSeriesAsDrilldown(e.point, series);

please help me on how to can I achieve drilldown via $.ajax call.

$(function () {    

// Create the chart
$('#container').highcharts({
    chart: {
        type: 'column',
        events: {
            drilldown: function (e) {
                if (!e.seriesOptions) {

                    var chart = this,
                        drilldowns = {
                            'Animals': {
                                name: 'Animals',
                                data: [
                                    ['Cows', 2],
                                    ['Sheep', 3]
                                ]
                            },
                            'Fruits': {
                                name: 'Fruits',
                                data: [
                                    ['Apples', 5],
                                    ['Oranges', 7],
                                    ['Bananas', 2]
                                ]
                            },
                            'Cars': {
                                name: 'Cars',
                                data: [
                                    ['Toyota', 1],
                                    ['Volkswagen', 2],
                                    ['Opel', 5]
                                ]
                            }
                        },
                        series = drilldowns[e.point.name];

                    // Show the loading label
                    chart.showLoading('Simulating Ajax ...');

                    setTimeout(function () {
                        chart.hideLoading();
                        chart.addSeriesAsDrilldown(e.point, series);
                    }, 1000);
                }

            }
        }
    },
    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: []
    }
})

});

like image 586
alhashmiya Avatar asked Jun 25 '26 20:06

alhashmiya


1 Answers

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);
                    });
                }
            }
like image 140
Paweł Fus Avatar answered Jun 27 '26 13:06

Paweł Fus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!