DoumiLo
Posts: 35
Joined: Wed Jan 20, 2021 2:09 pm

Dynamically renaming series

Hello!

I have a problem to dynamically rename the series after chart load. It's working at first but when I press one of the range selector's grouping button (by week, by month, by year) the default names (Series 1, Series 2 etc) reappears.

I have tried this:

Code: Select all

let arr = ['Montreal', 'Boston', 'Paris', 'Tokyo', 'New York'];

for (var i = 0; i < arr.length; i++) {
  chart.series[i].name = arr[i];
}
chart.reflow();

and with chart.update like this:

Code: Select all

let arr = ['Montreal', 'Boston', 'Paris', 'Tokyo', 'New York'];

chart.update({
  chart: {
      events: {
          redraw: function() {

            for (var i = 0; i < arr.length; i++) {
              this.series[i].name = arr[i];
            }

          }
      }
  },
});
chart.reflow();

Can you see what I'm doing wrong?

Thank you for all your good support!
DoumiLo
Posts: 35
Joined: Wed Jan 20, 2021 2:09 pm

Re: Dynamically renaming series

Ok I found the solution. I should use this instead in my loop:

Code: Select all

let arr = ['Montreal', 'Boston', 'Paris', 'Tokyo', 'New York'];

for (var i = 0; i < arr.length; i++) {
  
  chart.series[i].update({name:arr[i]}, false);
  
}
chart.reflow();

Can you tell me what is the "false" option?

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

Re: Dynamically renaming series

Hi DoumiLo,

Congratulations on solving the problem.

In this case false prevents chart from being redrawn after update. Usually this option is used when the chart or chart's elements are updated frequently to improve general performance.
API reference:https://api.highcharts.com/class-refere ... ies#update

Let me know if you have any further questions.
Best regards!
Mateusz Bernacik
Highcharts Developer

Return to “Highcharts Stock”