fpc
Posts: 3
Joined: Tue Apr 02, 2019 11:04 am

Add/remove Plotlines dynamically

Dear Highstock tech support team,

In the application I am building, my team implemented dynamic adding and removing of PlotLines by using YAxis.addPlotine() and PlotLine.destroy(), which seemed to be working as expected. However, after implementing other unrelated features, we noticed that some API methods to update the chart (for example, YAxis.update()) would, as a side effect, show all previously destroyed PlotLines.

After some debugging, I understand that all the PlotLines are cached in chart.userOptions.plotLines even after calling PlotLine.destroy(), but I do not know whether this is a bug or intended behavior.

Here is a simplified demo of my problem:
https://stackblitz.com/github/francisco ... harts-demo

The problem can be seen by following these steps:

click 'Add Line' 3 times
click 'Remove Line' 2 times
click 'Update Y Axis Options'


The lines that were removed are now rendered again in the chart.

Help would be much appreciated.

Best regards,
Francisco
rafalS
Posts: 2665
Joined: Thu Jun 14, 2018 11:40 am

Re: Add/remove Plotlines dynamically

Hi Francisco,

Thank you for writing to us with your concerns.

Actually, element.destroy() method only removes SVG element, but does not delete its config. Instead, you should use yAxis.removePlotLine(id) method if you want to remove your plotLine: https://api.highcharts.com/class-refere ... vePlotLine

Here is a correct example of doing it: https://jsfiddle.net/BlackLabel/16Lk5sg8 (commented line 20 is your way of doing it which doesn't work).

Let me know if you have any further questions.

Best regards!
Rafal Sebestjanski,
Highcharts Team Lead
fpc
Posts: 3
Joined: Tue Apr 02, 2019 11:04 am

Re: Add/remove Plotlines dynamically

Thank you for the quick reply. That was very helpful.
Igarcia
Posts: 1
Joined: Tue May 31, 2022 2:24 pm

Re: Add/remove Plotlines dynamically

Hello,

I found this post very useful in order to know how to use and change plotLines in charts.

However, there was no trace of this in the API documentation. In fact, the link from rafalS post that should show Axis.removePlotLine() just shows the Axis page, where neither removePlotLine() nor addPlotLine() methods can be found.

I wanted to raise awareness of this issue and ask for these pages and other that may have been misplaced to be restored.

Thank you for your help.
Best regards.
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: Add/remove Plotlines dynamically

Hi Igarcia,

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

Thanks for bringing it up. The issue has already been reported and hopefully it will be fixed soon. Here is the ticket:
https://github.com/highcharts/highcharts/issues/17052

Feel free to leave you feedback there.

In case of any questions feel free to contact us anytime.
Regards!
Mateusz Bernacik
Highcharts Developer

Return to “Highcharts Stock”