Highcharts:从地图深入到图表

时间:2018-11-05 09:30:09

标签: javascript jquery highcharts drilldown

请考虑使用Kuwait地图:

Kuwait Map

我想要当用户单击一个状态(例如-Al Jahrah)时,出现Al Jahrah系列的柱形图。例如:

Category For: Al Jahrah            Value For: Al Jahrah 
--------------------------------------------------------
Cat1                               10
Cat2                               12
Cat3                               3

我通过互联网搜索,但只看到国家/地区深入到各州。有可能吗?

谢谢

1 个答案:

答案 0 :(得分:1)

您可以创建两个函数,这些函数将负责创建不同类型的图表并在适当的事件中调用它们:

function mapChart() {
    Highcharts.mapChart('container', {
        chart: {
            map: 'countries/kw/kw-all'
        },

        title: {
            text: 'Highmaps basic demo'
        },

        subtitle: {
            text: 'Source map: <a href="http://code.highcharts.com/mapdata/countries/kw/kw-all.js">Kuwait</a>'
        },

        mapNavigation: {
            enabled: true,
            buttonOptions: {
                verticalAlign: 'bottom'
            }
        },

        colorAxis: {
            min: 0
        },

        series: [{
            data: data,
            name: 'Random data',
            point: {
                events: {
                    click: function() {
                        columnChart(this.name);
                        document.getElementById("back").style.display = "block"
                    }
                }
            },
            states: {
                hover: {
                    color: '#BADA55'
                }
            },
            dataLabels: {
                enabled: true,
                format: '{point.name}'
            }
        }]
    });

    document.getElementById("back").style.display = "none";
}

function columnChart(name) {
    var data = [1, 2, 3];

    if (name === "Al Jahrah") {
        data = [2, 2, 2];
    }

    Highcharts.chart('container', {
        title: {
            text: name
        },
        series: [{
            type: 'column',
            data: data
        }]
    });
}

mapChart();

实时演示:https://jsfiddle.net/BlackLabel/bnsjgt4z/

下面您可以找到从地图到图表的深入钻取的另一种解决方案:

https://www.highcharts.com/maps/demo/rich-info

https://www.highcharts.com/maps/demo/data-class-two-ranges