本文介绍了在图例中显示Series和colorAxis的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to have both colorAxis and series in the legend? http://jsfiddle.net/6k17dojn/ i see i can only show one at a time when I toggle this setting
colorAxis: { showInLegend: true, }

推荐答案

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

Currently to show a basic legend with colorAxis, you need to add some code to Highcharts core. This plugin below allows you to add colorAxis to a legend if showInLegend property is set to 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

这篇关于在图例中显示Series和colorAxis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 08:57