Highcharts显示/隐藏所选点的数据标签

时间:2014-12-21 18:44:05

标签: javascript charts highcharts

使用highcharts数据标签仍然遇到很大麻烦。现在我需要通过点击点来显示和隐藏数据标签。试过这个:

plotOptions: {
            series: {
                allowPointSelect : true,
                point: {
                    events: {
                        select /*click*/: function () {
                            this.options.dataLabels.enabled = !this.options.dataLabels.enabled;
                            this.update();
                        }
                    }
                }                
            }
        }

但是得到Uncaught TypeError: Cannot set property 'enabled' of undefined

将PlotOptions级别的事件指定为point.selectpoint.click,但是根据highcharts.com提供的示例,我无法获得任何帮助。

此外,我无法弄清楚我是应该使用点数还是通过阵列访问like series[0].data[1]等与某些系列一起工作? 谢谢。

1 个答案:

答案 0 :(得分:4)

将更新的媒体资源传递到Point.update() method

          point:{
                events:{
                    click: function(){
                        // determine toggle state
                        // on first click this.dataLabels is undefined...
                        var e = !this.dataLabels || this.dataLabels.enabled ? false : true;
                        this.update({
                            dataLabels:{
                                enabled: e
                            }
                        });
                    }
                }
            }

Here's an example切换它们。