我正在Highcharts中处理堆积柱形图。我要求在图例的每次单击上都应显示/隐藏该系列上的dataLabels,但不应隐藏该系列/堆栈。所以我只想隐藏/显示dataLabels。

我尝试了这个,并通过使用此命令使该系列停止隐藏:

events: {
    legendItemClick: function () {
        return false; // <== returning false will cancel the default action
    }
}


但单击图例后,我无法显示dataLabels。

这是Fiddle Link

最佳答案

legendItemClick: function (x) {
                    x.preventDefault()
                  var opt = x.target.chart.options.plotOptions.series;
    opt.dataLabels.enabled = !opt.dataLabels.enabled;
    x.target.chart.series[x.target.index].update(opt);
                  //x.target.chart.options.plotOptions.series.dataLabels.enabled=false
                   // <== returning false will cancel the default action
                    }

10-07 21:18