简体   繁体   English

高图:更改图例符号运行时

[英]Highcharts: change legend symbol runtime

Having a 'scatter' chart with custom marker/icon: 具有带有自定义标记/图标的“散布”图表:

series: [{
     marker: {
         symbol: 'url(http://www.highcharts.com/demo/gfx/sun.png)'
    }
}]

http://jsfiddle.net/sy6nb7fk http://jsfiddle.net/sy6nb7fk

Is there any way to replace legend icon when data series is deselected? 取消选择数据系列时,有什么方法可以替换图例图标?

ie use 'sun_disabled.png' 即使用“ sun_disabled.png”

You will have to do a update call to change the marker on certain events. 您将必须进行update调用才能在某些事件上更改标记。

You could do this in plotOptions.series.events.legendItemClick if the series is shown/hidden using the legend item only. 如果仅使用图例项显示/隐藏系列,则可以在plotOptions.series.events.legendItemClick执行此操作。 For example ( JSFiddle ): 例如( JSFiddle ):

plotOptions: {
    series: {
        events: {
            legendItemClick: function(event) {
                var imageName = (this.visible ? 'snow' : 'sun');

                this.update({ 
                    marker: { 
                        symbol: 'url(http://www.highcharts.com/demo/gfx/'+ imageName +'.png)' 
                    } 
                });
            }
        }
    }
}

If the series may be shown/hidden using hide() and show() function calls you could do the same using Series.events.hide and Series.events.show . 如果可以使用hide()show()函数调用显示/隐藏系列,则可以使用Series.events.hideSeries.events.show进行相同的操作。 For example ( JSFiddle ): 例如( JSFiddle ):

series: [{
    events: {
        hide: function() {
            this.update({ 
                marker: { 
                    symbol: 'url(http://www.highcharts.com/demo/gfx/snow.png)' 
                } 
            });
        },
        show: function() {
           this.update({ 
                marker: { 
                    symbol: 'url(http://www.highcharts.com/demo/gfx/sun.png)' 
                } 
            });
        }
    },
    marker: {
        symbol: 'url(http://www.highcharts.com/demo/gfx/sun.png)'
    },
    data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM