jacwright
Posts: 8
Joined: Wed Dec 08, 2010 4:52 pm

Refreshing legend labels

Is there a way to refresh/redraw the labels in the legend? I have a dynamically updating chart and would like to see the latest data values in the legend.

This is what I have currently in my legend options:

Code: Select all

labelFormatter: function() {
	return this.name + (this.data.length ? ' (' + this.data[this.data.length - 1].y + ')' : '');
}
It needs to be rerun and the text updated every time new data points are loaded.
jacwright
Posts: 8
Joined: Wed Dec 08, 2010 4:52 pm

Re: Refreshing legend labels

Nothing? No one has ever listed the latest value of a dynamically updating chart in the legend?
User avatar
SOMR
Posts: 119
Joined: Wed Nov 03, 2010 11:38 am
Location: Sydney, Australia

Re: Refreshing legend labels

You want to see only the latest added? Or you want to see all the legend included the latest added or maybe to see all the legend and only the latest is selected/visible and old legend is hidden?
jacwright
Posts: 8
Joined: Wed Dec 08, 2010 4:52 pm

Re: Refreshing legend labels

SOMR wrote:You want to see only the latest added? Or you want to see all the legend included the latest added or maybe to see all the legend and only the latest is selected/visible and old legend is hidden?
We want to see the numbers of the last added points in the legend.

We're using uglier less-readable charts for monitoring the amount of content we're collecting (twitter, blogs, etc.) with 6-8 content types on the chart. We have these charts up on a big monitor in the office that we can watch throughout the day to insure we our services are collecting appropriately and we need the last added points' values to be displayed in the legend next to the series name. It's too hard to pick out the numbers with 6-8 lines trying to match up colors. The chart gives us a good idea for the last several hours, the legend gives us solid numbers for where we're at now.

We don't hook up a mouse so mousing over the point won't work. These charts update every minute with the rolling average of the last 5 minutes, so we get a good idea of where we're at and whether any of the services are down or suffering in some way. And the latest numbers give us absolute knowledge of where we are at.
tonyx
Posts: 21
Joined: Sat Oct 09, 2010 5:05 pm

Re: Refreshing legend labels

after you created the chart, you can use

Code: Select all

chart.series[serieIndex].legendItem.attr("text", "your text here")
to change the value of the legend item. Alternatively, you can read / write this property

Code: Select all

chart.series[serieIndex].legendItem.element.textContent
jacwright
Posts: 8
Joined: Wed Dec 08, 2010 4:52 pm

Re: Refreshing legend labels

Thanks tonyx, the textContent property will work out great with some regex replacements.
tonyx
Posts: 21
Joined: Sat Oct 09, 2010 5:05 pm

Re: Refreshing legend labels

On that note, I'm actually trying to figure out how to redraw the bounding box after the legend item text has been changed. Because if I were to change the text of the legend to longer than it previously was, the bounding box would not resize long with it and everything just looks pretty awkward.
tonyx
Posts: 21
Joined: Sat Oct 09, 2010 5:05 pm

Re: Refreshing legend labels

Actually i just figured it out.

chart.isDirtyLegend = true;
chart.redraw();

will fix the bounding box problem!
jacwright
Posts: 8
Joined: Wed Dec 08, 2010 4:52 pm

Re: Refreshing legend labels

Even better!!
Keerthi Hangal
Posts: 8
Joined: Fri Jan 07, 2022 6:00 am

Re: Refreshing legend labels

Hi Team,
Is there a way to enable back the disabled legend item when the chart series is updated?https://jsfiddle.net/gh/get/library/pur ... -addseries


Thanks in advance. :)
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: Refreshing legend labels

Hi Keerthi Hangal,

Welcome to our forum and thanks for contacting us with your question!

Could you provide me with some more details? In the demo that you shared all legend items are already enabled and I'm not quite sure what do you want to enable. Did I miss something?

Thanks in advance for clarification.
Regards!
Mateusz Bernacik
Highcharts Developer
Keerthi Hangal
Posts: 8
Joined: Fri Jan 07, 2022 6:00 am

Re: Refreshing legend labels

Hi mateusz, Thank you for the quick reply.
By default, I have all the legends enabled. But, If I disable the series1 legend and hit Add Series button, I need both series1 and series 2 legend to be Enabled.
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: Refreshing legend labels

Hi Keerthi Hangal,

Thanks for clarification. If series are disabled and you want to show them again when new series is being added, then you should loop over series array and call show() method on them.
Demo:https://jsfiddle.net/BlackLabel/de5us8z1/
API reference: https://api.highcharts.com/class-refere ... eries#show

Let me know if that was what you were looking for!
Regards!
Mateusz Bernacik
Highcharts Developer
Keerthi Hangal
Posts: 8
Joined: Fri Jan 07, 2022 6:00 am

Re: Refreshing legend labels

This is exactly what I was looking for. However, adding visible : true also worked.
Thank you. :)

Regards,
Keerthi Hangal
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: Refreshing legend labels

You're welcome! In case of any further questions, feel free to contact us again.
Mateusz Bernacik
Highcharts Developer

Return to “Highcharts Usage”