0

I am trying to create a line chart using the danielgindi/ios-charts library. enter image description here

This works quite well so far. However, I cannot set the values on the left axis in 250 steps as desired.You can see my last attempt here:

ChartYAxis *leftAxis = self.lineChartView.leftAxis;
leftAxis.labelTextColor = [UIColor colorNamed:@"ColorGraphSD"];
leftAxis.axisMinimum = 0;
leftAxis.axisMaximum = ceil(maxValue / 250.0) * 250;
leftAxis.drawGridLinesEnabled = YES;
leftAxis.drawZeroLineEnabled = NO;
leftAxis.granularityEnabled = NO;
leftAxis.granularity = .1;
leftAxis.axisRange = 250;
leftAxis.labelCount = ceil(maxValue / 250.0);

Debugger tells me leftAxis.labelCount = 8; and leftAxis.axisMaximum = 2000;

All I want is a line at 250,500,750....

How to do that?

1 Answer 1

1

You need 9 labels, not 8, because you need to include the Zero label.

Also, setting .granularity = 250.0; will give you "steps" at 250 increments.

Example:

ChartYAxis *leftAxis = _chartView.leftAxis;
leftAxis.labelFont = [UIFont systemFontOfSize:10.f];
leftAxis.labelPosition = YAxisLabelPositionOutsideChart;
leftAxis.axisMinimum = 0.0;
leftAxis.axisMaximum = 2000.0;

// use .granularity
leftAxis.granularity = 250.0;

// we need 9 labels to include the Zero label
leftAxis.labelCount = 9;

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.