【问题标题】:highmaps get country name on click eventhighmaps 在点击事件上获取国家名称
【发布时间】:2015-10-23 22:51:13
【问题描述】:
$('#container').highcharts('Map', {

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

        subtitle : {
            text : 'Source map: <a href="http://code.highcharts.com/mapdata/custom/africa.js">Africa</a>'
        },

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

        colorAxis: {
            min: 0
        },

        series : [{
            data : data,
            mapData: Highcharts.maps['custom/africa'],
            joinBy: 'hc-key',
            name: 'Random data',
            states: {
                hover: {
                    color: '#BADA55'
                }
            },
            dataLabels: {
                enabled: true,
                format: '{point.name}'
            }
        }]
    });
});

http://jsfiddle.net/gh/get/jquery/1.11.0/highslide-software/highcharts.com/tree/master/samples/mapdata/custom/africa 我正在使用这个小提琴,我想在该国家/地区的点击事件中获取国家/地区名称。任何人都可以通过示例或链接到此 API 来帮助我吗?我阅读了 API 但找不到,我想我错过了一些观点。 在此先感谢

【问题讨论】:

    标签: onclick highmaps


    【解决方案1】:

    很简单,只需添加以下内容:

        plotOptions:{
            series:{
                point:{
                    events:{
                        click: function(){
                            alert(this.name);
                        }
                    }
                }
            }
        }
    

    点范围内的this 代表点击的点,因此您可以访问它的属性。

    http://jsfiddle.net/farz5vq2/

    【讨论】:

    • 简单高效。
    • 另外,here 的 highcharts 演示演示了在单击地图点时打开一个 url。
    • 有没有办法在事件范围内访问 vue 数据属性基本上,如果我们在 vue 中有一个数据属性作为 selectedCountry 可以显示为 {{ selectedCountry }},那么是否可以获得并使用 this.selectedCountry = this.name 更新它?
    猜你喜欢
    • 2016-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多