问题描述
图例中是否可以同时包含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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!