3

I've looked everywhere and tried various approaches and cannot figure this out. How do I position the xAxis at the bottom of the line chart?

In viewDidLoad:

[self initChartProperties];
[self updateChartData:5];

initChartProperties:

- (void)initChartProperties2 {
    _chartView.delegate = self;
    _chartView.descriptionText = @"";
    _chartView.noDataTextDescription = @"You need to provide data for the chart.";
    _chartView.dragEnabled = YES;
    _chartView.pinchZoomEnabled = YES;
    _chartView.legend.enabled = NO;
    [_chartView setScaleEnabled:YES];

    _chartView.leftAxis.customAxisMax = 21;
    _chartView.leftAxis.customAxisMin = 0;
    _chartView.leftAxis.drawZeroLineEnabled = NO;
    _chartView.leftAxis.enabled = YES;

    _chartView.xAxis.axisLineWidth = 2.0f;
    _chartView.xAxis.drawAxisLineEnabled = YES;

    _chartView.rightAxis.enabled = NO;

    [_chartView.viewPortHandler setMaximumScaleY: 2.f];
    [_chartView.viewPortHandler setMaximumScaleX: 2.f];
}

updateChartData:

- (void)updateChartData:(int)count {
    NSMutableArray *xVals = [[NSMutableArray alloc] init];
    NSMutableArray *yVals = [[NSMutableArray alloc] init];

    for (int i = 0; i < count; i++) {
        [xVals addObject:[@(i) stringValue]];
    }

    for (int i = 0; i < count; i++) {
        [yVals addObject:[[ChartDataEntry alloc] initWithValue:i xIndex:i]];
    }

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

    set1.lineWidth = 1.0;
    set1.circleRadius = 0.0;
    set1.drawCircleHoleEnabled = NO;
    set1.valueFont = [UIFont fontWithName:@"HelveticaNeue-Light" size:9.0f];

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

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

    _chartView.data = data;
}

Result: line graph

I just want the xAxis values to be rendered at the bottom of the graph, not the top. Sorry for the seemingly simple question. Appreciate any help.

2 Answers2

4

Nevermind - finally figured it out

_chartView.xAxis.labelPosition = XAxisLabelPositionBottom;
0

In the most recent version (currently 3.0) you can do it with

_chartView.xAxis.labelPosition = XAxis.LabelPosition.bottom
Chris Balavessov
  • 805
  • 8
  • 14