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

Line Chart Line is not drawing properly for the large yValues #307

Closed
faizandedia opened this issue Aug 19, 2015 · 7 comments
Closed

Line Chart Line is not drawing properly for the large yValues #307

faizandedia opened this issue Aug 19, 2015 · 7 comments

Comments

@faizandedia
Copy link

I tried to integrate line chart but it seems it is not drawing it properly for the large yValues see the attached screenshot. see the screenshot. for small values it works fine.

screen shot 2015-08-19 at 9 22 17 am

@liuxuan30
Copy link
Member

You need to provide the data sets so we can try reproduce. From the screenshot we can't tell what's wrong.

@faizandedia
Copy link
Author

Here is the data I have

    NSMutableArray *xVals = [[NSMutableArray alloc] initWithObjects:@“Jun“,@”Jul”,@“Aug”, nil];


    NSMutableArray *yVals = [[NSMutableArray alloc] init];
    [yVals addObject:[[ChartDataEntry alloc] initWithValue:12238 xIndex:0]];
    [yVals addObject:[[ChartDataEntry alloc] initWithValue:14022 xIndex:1]];
    [yVals addObject:[[ChartDataEntry alloc] initWithValue:9286 xIndex:2]];

    LineChartDataSet *set1 = [[LineChartDataSet alloc] initWithYVals:yVals label:@"DataSet 1"];

    set1.lineWidth = 3.0;
    set1.circleRadius = 7.0;
    [set1 setColor:[UIColor whiteColor]];
    [set1 setCircleColor:[UIColor whiteColor]];
    set1.circleHoleColor = [UIColor colorWithRed:0 green:155/255.0f blue:223/255.0f alpha:1.0];
    set1.drawCircleHoleEnabled = true;
    set1.drawValuesEnabled = false;
    set1.drawFilledEnabled = false;

    NSMutableArray *dataSets = [[NSMutableArray alloc] init];
    [dataSets addObject:set1];


    LineChartData *data = [[LineChartData alloc] initWithXVals:xVals dataSets:dataSets];
    chartView.data = data;

@liuxuan30
Copy link
Member

giving the value 9286, 12238, 14022, I think your distance on y axis is fine. Have you looked at what's the yAxis range?

@faizandedia
Copy link
Author

I set the values for customAxisMin and Max, still giving the same result:

    double maxValue = MAX([value1 doubleValue], [value2 doubleValue]);
    maxValue = MAX(maxValue, [value3 doubleValue]);

    double minValue = MIN([value1 doubleValue], [value2 doubleValue]);
    minValue = MIN(minValue, [value3 doubleValue]);

    chartView.leftAxis.customAxisMax = maxValue;
    chartView.leftAxis.customAxisMin = minValue;
    chartView.leftAxis.startAtZeroEnabled = false;

@liuxuan30
Copy link
Member

should be your setup problem, I don't have trouble with customAxisMax.
What's the order of calling chartView.data = yourData and chartView.leftAxis.customAxisMax = maxValue?
Have you tried to call notifyDataSetChanged after you changed the properties?

@faizandedia
Copy link
Author

I tried to do that as well, still same output. Here is the full sample code

chartView.descriptionText = @"";
chartView.noDataTextDescription = @"";
chartView.noDataText = @"";

chartView.dragEnabled = NO;
[chartView setScaleEnabled:NO];
chartView.pinchZoomEnabled = NO;
chartView.drawGridBackgroundEnabled = NO;

chartView.backgroundColor = [UIColor clearColor];



ChartXAxis *xAxis = chartView.xAxis;
xAxis.labelFont = [UIFont systemFontOfSize:12.f];
xAxis.labelTextColor = UIColor.whiteColor;
xAxis.drawGridLinesEnabled = NO;
xAxis.drawAxisLineEnabled = NO;
xAxis.spaceBetweenLabels = 1.0;
xAxis.labelPosition = XAxisLabelPositionBottom;
xAxis.xOffset = 0;
xAxis.yOffset = 0;

ChartYAxis *leftAxis = chartView.leftAxis;
leftAxis.labelTextColor = [UIColor colorWithRed:51/255.f green:181/255.f blue:229/255.f alpha:1.f];
leftAxis.drawGridLinesEnabled = NO;
leftAxis.spaceTop = 0;
leftAxis.spaceBottom = 0;


chartView.rightAxis.enabled = NO;
chartView.leftAxis.enabled = NO;
chartView.legend.enabled = NO;

NSMutableArray *xVals = [[NSMutableArray alloc] initWithObjects:@“Jun“,@”Jul”,@“Aug”, nil];
NSMutableArray *yVals = [[NSMutableArray alloc] init];
[yVals addObject:[[ChartDataEntry alloc] initWithValue:12238 xIndex:0]];
[yVals addObject:[[ChartDataEntry alloc] initWithValue:14022 xIndex:1]];
[yVals addObject:[[ChartDataEntry alloc] initWithValue:9286 xIndex:2]];
LineChartDataSet *set1 = [[LineChartDataSet alloc] initWithYVals:yVals label:@"DataSet 1"];

    set1.lineWidth = 3.0;
    set1.circleRadius = 7.0;
    [set1 setColor:[UIColor whiteColor]];
    [set1 setCircleColor:[UIColor whiteColor]];
    set1.circleHoleColor = [UIColor colorWithRed:0 green:155/255.0f blue:223/255.0f alpha:1.0];
    set1.drawCircleHoleEnabled = true;
    set1.drawValuesEnabled = false;
    set1.drawFilledEnabled = false;

    NSMutableArray *dataSets = [[NSMutableArray alloc] init];
    [dataSets addObject:set1];

    double maxValue = MAX([value1 doubleValue], [value2 doubleValue]);
    maxValue = MAX(maxValue, [value3 doubleValue]);

    double minValue = MIN([value1 doubleValue], [value2 doubleValue]);
    minValue = MIN(minValue, [value3 doubleValue]);

    chartView.leftAxis.customAxisMax = maxValue;
    chartView.leftAxis.customAxisMin = minValue;
    chartView.leftAxis.startAtZeroEnabled = false;

    LineChartData *data = [[LineChartData alloc] initWithXVals:xVals dataSets:dataSets];
    chartView.data = data;
    [chartView notifyDataSetChanged];

@faizandedia
Copy link
Author

The issue is fixed, somehow view was clipping the line from maxValue, I added extra margin in maxValue so It can be inside the view.

chartView.leftAxis.customAxisMax = maxValue + 500; // margin

Thanks for the help.. :)

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

2 participants