amcharts / amcharts5

The newest, fastest, and most advanced amCharts charting library for JavaScript and TypeScript apps.
Other
345 stars 92 forks source link

Alternative() method in Color class #1726

Closed dmytro-kuz closed 2 weeks ago

dmytro-kuz commented 2 weeks ago

Question I am trying to set the color of the bullet label so it is clearly visible on the series. Depending on the shade of the series, I want to set either black or white text, similar to how the autoTextColor option works. As far as I understand, this can be achieved using the method described here: https://www.amcharts.com/docs/v5/reference/color/#alternative_method. This method returns a new Color object based on either lightAlternative or darkAlternative, depending on which one is more contrasting with the series color. Maybe I misunderstood how it works or made a mistake in the demo. But for me, in both cases (light and dark colors of the series), the white color is returned. Can you please tell me how to achieve the desired result?

Codepen: https://codepen.io/Dmytro-Kuz/pen/JjQNPPZ?editors=1010

Additional context image

martynasma commented 2 weeks ago

Yes, the am5.Color.alternative() function takes three parameters, e.g.:

am5.Color.alternative(am5.color(color), am5ColorLight, am5ColorDark)
dmytro-kuz commented 2 weeks ago

My bad. I did not consider which color will be applied for white and for dark contrast. Thank you very much for your help