导出图例中没有隐藏系列标签的图表

时间:2019-01-17 16:57:39

标签: highcharts

在隐藏某些系列后导出我的图表时,它仍在图例中显示其标签(隐藏)。有没有办法只显示图例中活动系列的标签?

Demo chart from Highcharts. "Installation" and "Sales & Distribution" series are hidden but their labels appear in the legend.

1 个答案:

答案 0 :(得分:1)

默认情况下,Highharts不支持此行为,但是您可以轻松地包装init方法,并根据系列可见性设置showInLegend选项进行导出:

Highcharts.wrap(Highcharts.Chart.prototype, 'init', function(proceed, options, callback) {
    if (options.chart && options.chart.forExport && options.series) {
        $.each(options.series, function() {
            if (this.visible === false) {
                this.showInLegend = false;
            }
        });
    }

    return proceed.call(this, options, callback);
});

实时演示:http://jsfiddle.net/BlackLabel/x2gy7f0q/

文档:https://www.highcharts.com/docs/extending-highcharts/extending-highcharts