djoshi
Posts: 61
Joined: Fri Mar 26, 2021 5:16 pm

Rounding up data to one decimal point

Hi

This is how may plot current looks.
noise plot.png
noise plot.png (84.11 KiB) Viewed 1482 times
The data is an analogue signal converted to a digital value. The conversion will add a little noise.

When data is plotted, is possible that data can be rounded to only 1 decimal point? So that the plot simple displays as 0, in such circumstances?
hubert.k
Posts: 1164
Joined: Mon Apr 11, 2022 11:48 am

Re: Rounding up data to one decimal point

Hi djoshi!
We appreciate you reaching out to us!

To add a custom numeric formatting on axis labels you can use a yAxis.labels.format property and use {value} with formatting, for example {value:.1f} (to round labels to one decimal point). You can do the same in tooltip using a tooltip.valueDecimals property. If you want to round your data, you should to this before passing it to chart configuration, e.g. using JavaScript below chart config.

Demo: https://jsfiddle.net/BlackLabel/2t6fzguq/
API Reference: https://api.highcharts.com/highcharts/y ... els.format
https://api.highcharts.com/highcharts/t ... ueDecimals

Feel free to ask any further questions!
Kind regards!
Hubert Kozik
Highcharts Developer
djoshi
Posts: 61
Joined: Fri Mar 26, 2021 5:16 pm

Re: Rounding up data to one decimal point

Thanks, But the y axis is labelled correctly now, But the data seems to have the ripple.

Does this data need to be corrected for example if data is less then 0.05, make it 0? Or can the plots automatically make this adjustment?
hubert.k
Posts: 1164
Joined: Mon Apr 11, 2022 11:48 am

Re: Rounding up data to one decimal point

djoshi,
Unfortunately not. For performance reasons, Highcharts does not provide this functionality directly from API. You can make a loop through your data and round it as you would like to - you can it in the demo below.

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

Let me know if you have any further questions.
Kind regards!
Hubert Kozik
Highcharts Developer

Return to “Highcharts Stock”