Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Integer values on LineChart #2473

Closed
wadheraswati opened this issue May 25, 2017 · 8 comments
Closed

Show Integer values on LineChart #2473

wadheraswati opened this issue May 25, 2017 · 8 comments

Comments

@wadheraswati
Copy link

wadheraswati commented May 25, 2017

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;
@wadheraswati
Copy link
Author

@danielgindi please help soon

@thierryH91200
Copy link
Contributor

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

@wadheraswati
Copy link
Author

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

@liuxuan30
Copy link
Member

Check out ChartsDemo. There are plenty of them.

@wadheraswati
Copy link
Author

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.

@wadheraswati
Copy link
Author

wadheraswati commented May 26, 2017

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 <IChartValueFormatter>
@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.

@wadheraswati
Copy link
Author

wadheraswati commented May 26, 2017

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

@RubyRoshan
Copy link

RubyRoshan commented Jun 7, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants