Tr335
Posts: 27
Joined: Tue Jun 28, 2022 9:31 am

Dynamic data - how to set Plot lines

My plot line data is dynamic. I want to plot it when 'items' checkboxes are checked and based on which checkbox is clicked. And remove plotlines when item checkbox is unchecked. Can you please see my fiddle and let me know why my 'plotlinedata' is not getting set.

I tried using xAxis.plotLines[0].value = plotlinedata and yAxis[0].plotLines[0].value = plotlinedata; But could not get to work.

https://jsfiddle.net/2xozrs71/25/

Thank you.
michal.f
Posts: 1114
Joined: Thu Aug 12, 2021 12:04 pm

Re: Dynamic data - how to set Plot lines

Hello,

To update plotLines you need to use update() method on the axis.

Demo: https://jsfiddle.net/BlackLabel/bhd65usc/
API: https://api.highcharts.com/class-refere ... xis#update

Feel free to ask any further questions!
Best regards!
Michał Filipiec
Highcharts Developer
https://blacklabel.pl/highcharts/
Tr335
Posts: 27
Joined: Tue Jun 28, 2022 9:31 am

Re: Dynamic data - how to set Plot lines

Thank you very much.
michal.f
Posts: 1114
Joined: Thu Aug 12, 2021 12:04 pm

Re: Dynamic data - how to set Plot lines

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

Best regards!
Michał Filipiec
Highcharts Developer
https://blacklabel.pl/highcharts/
Tr335
Posts: 27
Joined: Tue Jun 28, 2022 9:31 am

Re: Dynamic data - how to set Plot lines

Hi, I have a follow up question.

1) To the fiddle you had sent, I tried adding 'checked=true' to plotline checkboxes, as I want the plotlines to be displayed on load by default. But I could not get it to work.

2) Also, If plotline value is an array. For example, plotline value of x-axis is 'value : [2,4]' instead of 'value: 2', I want both 2 and 4 values o be plotted on x axis (on load as I mentioned before).

May I know how I could achieve these. Thanks in advance.
michal.f
Posts: 1114
Joined: Thu Aug 12, 2021 12:04 pm

Re: Dynamic data - how to set Plot lines

Hi,
Tr335 wrote: Thu Aug 18, 2022 8:47 am 1) To the fiddle you had sent, I tried adding 'checked=true' to plotline checkboxes, as I want the plotlines to be displayed on load by default. But I could not get it to work.
Then you should move this logic to an external function and call it before adding listeners to checkboxes.
Tr335 wrote: Thu Aug 18, 2022 8:47 am 2) Also, If plotline value is an array. For example, plotline value of x-axis is 'value : [2,4]' instead of 'value: 2', I want both 2 and 4 values o be plotted on x axis (on load as I mentioned before).
As the API says, plotLines.value can only be a number, not an array. The array of objects is plotLines and to generate several lines on one axis you have to do it like this:

Code: Select all

plotLines: [{
  value: 2,
  color: 'green',
  width: 2,
  zIndex: 2
}, {
  value: 4,
  color: 'blue',
  width: 2,
  zIndex: 2
}]

Demo: https://jsfiddle.net/BlackLabel/4Lnchkbw/
API: https://api.highcharts.com/highcharts/xAxis.plotLines
https://api.highcharts.com/highcharts/x ... ines.value

Best regards!
Michał Filipiec
Highcharts Developer
https://blacklabel.pl/highcharts/
Tr335
Posts: 27
Joined: Tue Jun 28, 2022 9:31 am

Re: Dynamic data - how to set Plot lines

Thanks a lot.
hubert.k
Posts: 1164
Joined: Mon Apr 11, 2022 11:48 am

Re: Dynamic data - how to set Plot lines

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

Return to “Highcharts Usage”