0

Is it possible to have Highcharts drilldown on multiple graphs that are sharing the same data when one graph is clicked? As an example, I included a JSFiddle that uses the demo code (browser percentages). http://jsfiddle.net/Pq6gb/

var gridster;

$(function(){
gridster = $(".gridster ul").gridster({
    widget_base_dimensions: [150, 150],
    widget_margins: [5, 5],
    helper: 'clone',
    resize: {
        enabled: true,
        stop: function(e, ui, $widget) {
            for (var i = 0; i < Highcharts.charts.length; i++) {
                Highcharts.charts[i].reflow();
            }
        }
    }
}).data('gridster');
});

$(function () {

Highcharts.data({
    csv: document.getElementById('tsv').innerHTML,
    itemDelimiter: '\t',
    parsed: function (columns) {

        var brands = {},
            brandsData = [],
            versions = {},
            drilldownSeries = [];

        // Parse percentage strings
        columns[1] = $.map(columns[1], function (value) {
            if (value.indexOf('%') === value.length - 1) {
                value = parseFloat(value);
            }
            return value;
        });

        $.each(columns[0], function (i, name) {
            var brand,
                version;

            if (i > 0) {

                // Remove special edition notes
                name = name.split(' -')[0];

                // Split into brand and version
                version = name.match(/([0-9]+[\.0-9x]*)/);
                if (version) {
                    version = version[0];
                }
                brand = name.replace(version, '');

                // Create the main data
                if (!brands[brand]) {
                    brands[brand] = columns[1][i];
                } else {
                    brands[brand] += columns[1][i];
                }

                // Create the version data
                if (version !== null) {
                    if (!versions[brand]) {
                        versions[brand] = [];
                    }
                    versions[brand].push(['v' + version, columns[1][i]]);
                }
            }

        });

        $.each(brands, function (name, y) {
            brandsData.push({ 
                name: name, 
                y: y,
                drilldown: versions[name] ? name : null
            });
        });
        $.each(versions, function (key, value) {
            drilldownSeries.push({
                name: key,
                id: key,
                data: value
            });
        });

        // Create the chart
        $('#container').highcharts({
            chart: {
                type: 'pie'
            },
            title: {
                text: 'Browser market shares. November, 2013.'
            },
            subtitle: {
                text: 'Click the slices to view versions. Source: netmarketshare.com.'
            },
            plotOptions: {
                series: {
                    dataLabels: {
                        enabled: true,
                        format: '{point.name}: {point.y:.1f}%'
                    }
                }
            },

            tooltip: {
                headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
                pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>'
            }, 

            series: [{
                name: 'Brands',
                colorByPoint: true,
                data: brandsData
            }],
            drilldown: {
                series: drilldownSeries
            }
        })

    }
});
});

$(function () {

Highcharts.data({
    csv: document.getElementById('tsv').innerHTML,
    itemDelimiter: '\t',
    parsed: function (columns) {

        var brands = {},
            brandsData = [],
            versions = {},
            drilldownSeries = [];

        // Parse percentage strings
        columns[1] = $.map(columns[1], function (value) {
            if (value.indexOf('%') === value.length - 1) {
                value = parseFloat(value);
            }
            return value;
        });

        $.each(columns[0], function (i, name) {
            var brand,
                version;

            if (i > 0) {

                // Remove special edition notes
                name = name.split(' -')[0];

                // Split into brand and version
                version = name.match(/([0-9]+[\.0-9x]*)/);
                if (version) {
                    version = version[0];
                }
                brand = name.replace(version, '');

                // Create the main data
                if (!brands[brand]) {
                    brands[brand] = columns[1][i];
                } else {
                    brands[brand] += columns[1][i];
                }

                // Create the version data
                if (version !== null) {
                    if (!versions[brand]) {
                        versions[brand] = [];
                    }
                    versions[brand].push(['v' + version, columns[1][i]]);
                }
            }

        });

        $.each(brands, function (name, y) {
            brandsData.push({ 
                name: name, 
                y: y,
                drilldown: versions[name] ? name : null
            });
        });
        $.each(versions, function (key, value) {
            drilldownSeries.push({
                name: key,
                id: key,
                data: value
            });
        });

        // Create the chart
        $('#container2').highcharts({
            chart: {
                type: 'column'
            },
            title: {
                text: 'Browser market shares. November, 2013'
            },
            subtitle: {
                text: 'Click the columns to view versions. Source: netmarketshare.com.'
            },
            xAxis: {
                type: 'category'
            },
            yAxis: {
                title: {
                    text: 'Total percent market share'
                }
            },
            legend: {
                enabled: false
            },
            plotOptions: {
                series: {
                    borderWidth: 0,
                    dataLabels: {
                        enabled: true,
                        format: '{point.y:.1f}%'
                    }
                }
            },

            tooltip: {
                headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
                pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>'
            }, 

            series: [{
                name: 'Brands',
                colorByPoint: true,
                data: brandsData
            }],
            drilldown: {
                series: drilldownSeries
            }
        })

    }
});
});

There is a pie chart and a bar chart displaying the same data and can drilldown individually. I would like to click on any browser in the pie/bar chart and have both charts filter down to versions of that browser.

How would I go about doing this? Thanks.

1 Answer 1

1

Yes, it's possible. This is what you need to implement:

Note: You need to be aware of infinite loop (for example drillUp() in one chart will call drillup event, which will drillUp() first chart again.. ) - just add some flag to call drillUp/doDrilldown only once per user click.

Sign up to request clarification or add additional context in comments.

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.