Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I need to change dynamically legend labels and I was surprised when I have not found method like 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?

like image 345
redexp Avatar asked Jun 18 '13 12:06

redexp


People also ask

How do I change labels in legend?

Select your chart in Excel, and click Design > Select Data. Click on the legend name you want to change in the Select Data Source dialog box, and click Edit. Note: You can update Legend Entries and Axis Label names from this view, and multiple Edit options might be available.

How do I add labels to my legend?

In the Chart editor, under the 'Setup' tab, click the 'Add Label' box, under the 'Label' section. Select the cell range that includes your chart data. You should see your selected data displayed as labels in your chart.

How do I change the legend position in highcharts?

Set legend's layout, align and verticalAlign options as follows: legend: { layout: 'vertical', align: 'right', verticalAlign: 'middle', itemMarginTop: 10, itemMarginBottom: 10 }, By itemMarginTop/Bottom you can control the padding between the legend items.

How do I add extra legends in highcharts?

So best is to add your extraText in data while JSON creating and provide it to highcharts. At chart , it will show in desired format using the the code I posted in answer/fiddle. putting static text for "Extra" won't work in real scenario, so use the code in fiddle jsfiddle.net/wjnnt28p/3.


1 Answers

You can use update() function

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

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

like image 189
Sebastian Bochan Avatar answered Sep 25 '22 20:09

Sebastian Bochan