Xamarin - Datapoint value is rounding decimal place


#1

I am passing a value of 0.07 to a SChartLineSeries chart, but the label shows a value of 0.1. What do I set to make sure the values are not rounded

Thanks


#2

Hi theresa,

I may need a little more information, however it is possible that it’s a label formatting issue. Have you tried using SChartTickLabelFormatter to format your values to two decimal places (or however many you need)?

If that doesn’t work, could you let me know how many datapoints you have in your chart and perhaps post a screenshot of what you’re currently seeing?

Many thanks,

Sam


#3

Hi Sam, are there any examples for scharticklabelformatter in c#? This should read 0.07

 

thanks


#4

![](file:///Users/Vibes/Desktop/Screen%20Shot%202015-02-17%20at%202.57.40%20PM.png)


#5

Hi theresa,

You should be able to create an SChartTickLabelFormatter and then set its formatter property to an NSNumberFormatter (here’s the Xamarin link to the documentation).

You should be able to set MinimumFractionDigits to 2 (or however many digits you’d like to display after the decimal point).

If that doesn’t work and you have multiple datapoints you may have to set the major tick frequency.

I hope that’s of some help :smile:,

Sam


#6

Hi Sam, I was actually able to solve this issue by using this :

chart.YAxis.LabelFormatString = "%0.2f%";

seemed to have done the trick

thanks


#7

I followed your apporach (look below code) as well as Theresa’s approach. Both cases, even for numbers 100, it is drawing 100.00.

I only want decimals for decimal numbers only. suppose i have two datapoints in the chart 100 and 121.34. I want 100 to be drawn as 100, but 121.34 as 121.34

How do i do that? Please help

if(numberFormatter == nil){
        numberFormatter = [[NSNumberFormatter alloc] init];
        numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;
        numberFormatter.minimumFractionDigits = 2;
    }
    
    if(tickLabelFormatter == nil){
        tickLabelFormatter = [[SChartTickLabelFormatter alloc] init];
        [tickLabelFormatter setFormatter:numberFormatter];
    }
    
    self.schart.yAxis.labelFormatter = tickLabelFormatter;

#8

Never mind. found the anser

If you want the following

100 => 100

100.000 => 100

43.567 => 43.56

then use

numberFormatter.maximumFractionDigits = 2;

#9

Glad to hear you sorted it!