kmartynak
Posts: 69
Joined: Tue Dec 14, 2021 9:31 pm

problem with custom labels - growth value

Hi,

I have a problem with custom labels that are supposed to show percentage differences of values in a column. In one column only percentages are shown and in others not... why? what am i doing wrong? please help

I suppose there is an error here (but when I change it to 1000, the label with % is not shown everywhere)

Code: Select all

							for (let i = 1; i < data.length; i++) {
								const growthValue = Math.round((data[i].y / data[i - 1].y - 1) * 100);

this must work with any number...

What am I doing wrong that the chart is not shown? added all the code...
https://jsfiddle.net/de2ovax9/1/

thank you!!!!!!
Attachments
Bildschirmfoto 2023-01-24 um 11.02.42.png
Bildschirmfoto 2023-01-24 um 11.02.42.png (21.81 KiB) Viewed 168 times
kmartynak
Posts: 69
Joined: Tue Dec 14, 2021 9:31 pm

Re: problem with custom labels - growth value

with minus also...
jakub.s
Posts: 1228
Joined: Fri Dec 16, 2022 11:45 am

Re: problem with custom labels - growth value

Hi,

Thanks for the question!

With just a few changes:
1. Rendering labels always, not only when growthValue > 0
2. Rendering labels with - when the value is negative and with + when the value is positive.
I've managed to achieve this result:
chart.png
chart.png (19.83 KiB) Viewed 140 times


Here's the demo: https://jsfiddle.net/BlackLabel/h30wmyao/

Your demo did not work (it's in styled mode and there are no styles) so I'm not sure if that's supposed to look like this.

Let me know if that's what you were trying to achieve. If not, I'll gladly help you with finding your desired solution.

Best regards,
Jakub
Jakub
Highcharts Developer

Return to “Highcharts Usage”