Charts: Show Integer values on LineChart

Created on 25 May 2017  路  8Comments  路  Source: danielgindi/Charts

I have integrated LineChart in my project and it is working fine although I am not able to have non-float integer values in my graph. I have attached a screenshot for the same. I have added these settings for xlabel.

![screen shot 2017-05-25 at 4 53 59 pm](https://cloud.githubusercontent.com/assets/4290856/26448467/0a57aed2-416b-11e7-9f9a-e6567a31264a.png)

ChartXAxis *xAxis = leadsChartView.xAxis;
    xAxis.labelPosition = XAxisLabelPositionBottom;
    xAxis.labelFont = [UIFont fontWithName:@"HelveticaNeue-Light" size:12.f];
    xAxis.labelTextColor = [UIColor blackColor];
    xAxis.drawAxisLineEnabled = YES;
    xAxis.drawGridLinesEnabled = YES;
    xAxis.centerAxisLabelsEnabled = NO;
    xAxis.gridColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    xAxis.labelRotationAngle = 25;
    xAxis.granularityEnabled = YES;
    xAxis.granularity = 1.0;
    xAxis.forceLabelsEnabled = YES;

Most helpful comment

It was this earlier

screen shot 2017-05-25 at 4 53 59 pm

and now I have achieved this
screen shot 2017-05-26 at 2 42 44 pm

All 8 comments

@danielgindi please help soon

use formatter

 //Current Values                    what you want
            let format = NumberFormatter()
            format.numberStyle = NumberFormatter. none
            let formatter = DefaultValueFormatter(formatter: format)
            xAxis.setValueFormatter(formatter)

https://developer.apple.com/reference/foundation/numberformatter.style/1408907-none

I am using Objective C and this sets the xaxis values formatter not what is shown in the graph.

Check out ChartsDemo. There are plenty of them.

I have solved the issue. Here is the code.
```
set1 = [[LineChartDataSet alloc] initWithValues:values label:@""];
set1.drawIconsEnabled = NO;
set1.valueFormatter = [[SetValueFormatter alloc] init];

In SetValueFormatter

@interface SetValueFormatter : NSObject

@end

@implementation SetValueFormatter

  • (NSString * _Nonnull)stringForValue:(double)value entry:(ChartDataEntry * _Nonnull)entry dataSetIndex:(NSInteger)dataSetIndex viewPortHandler:(ChartViewPortHandler * _Nullable)viewPortHandler {
    return [NSString stringWithFormat:@"%d",(int)entry.y];
    }

@end

```

Hope it helps other people as well.

I have solved the issue. Here is the code.
```
set1 = [[LineChartDataSet alloc] initWithValues:values label:@""];
set1.valueFormatter = [[SetValueFormatter alloc] init];

In SetValueFormatter

@interface SetValueFormatter : NSObject


@implementation SetValueFormatter

  • (NSString * _Nonnull)stringForValue:(double)value entry:(ChartDataEntry * _Nonnull)entry dataSetIndex:(NSInteger)dataSetIndex viewPortHandler:(ChartViewPortHandler * _Nullable)viewPortHandler {
    return [NSString stringWithFormat:@"%d",(int)entry.y];
    }
    ```
    Hope it helps other people as well.

It was this earlier

screen shot 2017-05-25 at 4 53 59 pm

and now I have achieved this
screen shot 2017-05-26 at 2 42 44 pm

Hi,

I am using the below code :
-(NSString * _Nonnull)stringForValue:(double)value entry:(ChartDataEntry * _Nonnull)entry dataSetIndex:(NSInteger)dataSetIndex viewPortHandler:(ChartViewPortHandler * _Nullable)viewPortHandler{ if(_SelectedGraph.type==FPStationGraphTypeWind){ return [NSString stringWithFormat:@"%@",[_SelectedGraph.arrayDirections objectAtIndex:dataSetIndex]]; } else{ return [NSString stringWithFormat:@"%@",@""]; } }

LineChartDataSet *dataSet = [[LineChartDataSet alloc]initWithValues:arrayXYValue label:_SelectedGraph.graphLineText]; [dataSet setValueColors:@[[UIColor whiteColor]]]; [dataSet setValueFont:[UIFont fontWithName:@"HelveticaNeue" size:13.0]]; dataSet.valueFormatter = self;
but it did not get called on this method.

Please suggest as it was running before

Was this page helpful?
0 / 5 - 0 ratings

Related issues

newbiebie picture newbiebie  路  3Comments

PrashantKT picture PrashantKT  路  3Comments

kwstasna picture kwstasna  路  3Comments

JW00332 picture JW00332  路  4Comments

sjdevlin picture sjdevlin  路  3Comments