himmat
Posts: 28
Joined: Mon Dec 28, 2020 5:36 pm

Updating line color dynamically?

Hi!

I am trying to change the colors of my chart after an event: https://jsfiddle.net/mxwvgL8t/4/

It looks like I am updating the value successfully (according to console.logs), but the change isn't being represented in the chart. Could anyone please advise?
dominik.c
Posts: 2081
Joined: Fri Aug 07, 2020 7:07 am

Re: Updating line color dynamically?

Hello himmat!

We appreciate you reaching out to us!

If you want to update the line color you need to use the update method.

API references:
https://api.highcharts.com/highcharts/series.line.color
https://api.highcharts.com/class-refere ... ies#update

Demo:
https://jsfiddle.net/BlackLabel/hb9uyno6/

Let me know if that was what you were looking for!
Best regards!
Dominik Chudy
Highcharts Developer
himmat
Posts: 28
Joined: Mon Dec 28, 2020 5:36 pm

Re: Updating line color dynamically?

Worked perfectly, thank you very much!
dominik.c
Posts: 2081
Joined: Fri Aug 07, 2020 7:07 am

Re: Updating line color dynamically?

You're welcome!

In case of any further questions, feel free to contact us again.
Dominik Chudy
Highcharts Developer
BilldaCat
Posts: 11
Joined: Fri Jun 24, 2022 6:46 pm

Re: Updating line color dynamically?

I'm having a similar problem, but I need to get the value of the changed color. The goal is to store all the changes the user makes into a database, and then re-render the chart if they come back to it later.

The problem is the series color never seems to update in the options object, even though it absolutely changes. See fiddle/console.

https://jsfiddle.net/rdyvq3a4/2/

Despite changing the color to red, the console logs #aaaaaa for both before and after the change.

How can I get/save the current color properly?
hubert.k
Posts: 1164
Joined: Mon Apr 11, 2022 11:48 am

Re: Updating line color dynamically?

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

You can get a color of series from this object:

Code: Select all

selected_chart.series[0].color
not from selected_chart.series[0]options.

Demo: https://jsfiddle.net/BlackLabel/0fqyhrgn/

Feel free to ask any further questions.
Kind regards!
Hubert Kozik
Highcharts Developer
BilldaCat
Posts: 11
Joined: Fri Jun 24, 2022 6:46 pm

Re: Updating line color dynamically?

Perfect, thank you for the help!
hubert.k
Posts: 1164
Joined: Mon Apr 11, 2022 11:48 am

Re: Updating line color dynamically?

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

Return to “Highcharts Stock”