温馨提示:本文翻译自stackoverflow.com,查看原文请点击:highcharts - Show Series and colorAxis both in Legend
highcharts

highcharts - 在图例中显示Series和colorAxis

发布于 2020-03-27 10:27:11

图例中是否可以同时包含colorAxis和series?http://jsfiddle.net/6k17dojn/我看到在切换此设置时一次只能显示一个
colorAxis: { showInLegend: true, }

查看更多

查看更多

提问者
user4772933
被浏览
501
ppotaczek 2019-07-03 21:25

当前,要使用显示一个基本图例colorAxis,您需要向Highcharts核心添加一些代码。colorAxis如果showInLegend属性设置为,下面的此插件可让您添加图例false

(function(H) {
    H.addEvent(H.Legend, 'afterGetAllItems', function(e) {
        var colorAxisItems = [],
            colorAxis = this.chart.colorAxis[0],
            i;

        if (colorAxis && colorAxis.options) {
            if (colorAxis.options.dataClasses) {
                colorAxisItems = colorAxis.getDataClassLegendSymbols();
            } else {
                colorAxisItems.push(colorAxis);
            }
        }

        i = colorAxisItems.length;
        while (i--) {
            e.allItems.unshift(colorAxisItems[i]);
        }
    });
}(Highcharts))

现场演示: http : //jsfiddle.net/BlackLabel/hs1zeruy/

API参考: https : //api.highcharts.com/highcharts/colorAxis.showInLegend

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