BilldaCat
Posts: 11
Joined: Fri Jun 24, 2022 6:46 pm

Accessing series after addSeries? (and other dynamic changes to a chart)

I'm trying to write a 'chart editor' essentially where a user can add additional series, change the line colors, and so forth. Save the 'chart' to a database (which would be the json used to reconstruct the chart), so they can pull it up and continue editing later, share it, etc.

Adding is easy -- usual call to addSeries works fine, chart looks great.

The problem is when I want to save this chart, dynamically added series aren't in the userOptions. Nor is the line color, but I learned how to grab that. I'm guessing I need to get all the visible series through chart.series, loop over everything, and then save essentially a json object of everything I need to re-render the chart later.

Is there a better/easier way to get that data? I was ideally hoping to use userOptions, but that doesn't look like a good solution. Just want to make sure I'm not going down the wrong path here.
kamil.m
Posts: 892
Joined: Thu May 19, 2022 1:33 pm

Re: Accessing series after addSeries? (and other dynamic changes to a chart)

Hi there,

Thank you for contacting us.

You are right, when a new series is created by chart.addSeries, it is not available in the chart.userOptions.
Looping over an array of chart.series is a good idea, but maybe this one will suit you better:

When using a chart.addSeries method, the return of it is a new series. You can store that in a variable, and access later (or send it to your database).
DEMO: https://jsfiddle.net/BlackLabel/sfyhv8j2/
API Reference: https://api.highcharts.com/class-refere ... #addSeries

Let me know if that is what you were looking for,
Best regards!
Kamil Musiałowski
Highcharts Developer

Return to “Highcharts Usage”