javascript Highcharts:图表创建后如何设置图例标签名称?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17168793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 07:20:43  来源:igfitidea点击:

Highcharts: how to set legend label name after chart created?

javascripthighcharts

提问by redexp

I need to change dynamically legend labels and I was surprised when I have not found method like chart.legend.setLabels()

我需要动态更改图例标签,当我没有找到类似的方法时,我感到很惊讶 chart.legend.setLabels()

I tried this

我试过这个

chart.legend.allItems[0].name = 'bla bla'
chart.legend.redraw()

nothing happend

什么都没发生

tried to change options

试图改变选项

chart.options.legend.labels[0].name = 'bla bla'
chart.redraw()

nothing happend

什么都没发生

So is there way to change legend label name?

那么有没有办法更改图例标签名称?

回答by Sebastian Bochan

You can use update() function

您可以使用 update() 函数

 chart.legend.allItems[0].update({name:'aaa'});

http://jsfiddle.net/bL5ZM/1/

http://jsfiddle.net/bL5ZM/1/

回答by Magnus O.

You could also use

你也可以使用

chart.series[0].update({ name: "hello"});

http://jsfiddle.net/bL5ZM/149/

http://jsfiddle.net/bL5ZM/149/