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?
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.
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.
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.
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.
You can use update() function
chart.legend.allItems[0].update({name:'aaa'});
http://jsfiddle.net/bL5ZM/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With