Search code examples
iosiphonechartsios-charts

Ios Charts Left axis not showing labels few cases


I am using ios-charts library (Ios Charts) for graphs (line , bar).my issue is that few cases y axis labels are not showing.

please help me to resolve this.

here what my code is

ChartYAxis *leftAxis = _barChartView.leftAxis;
leftAxis.startAtZeroEnabled = YES;
leftAxis.labelFont = [UIFont systemFontOfSize:10.f];
leftAxis.labelCount = 8;
leftAxis.valueFormatter = [[NSNumberFormatter alloc] init];
leftAxis.valueFormatter.maximumFractionDigits = 1;
leftAxis.axisLineColor = [UIColor blackColor];
leftAxis.axisLineWidth = 1.0;

leftAxis.labelPosition = YAxisLabelPositionOutsideChart;
leftAxis.spaceTop = 0.15;

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

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

BarChartData *data = [[BarChartData alloc] initWithXVals:xvalues dataSets:dataSets];
[data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:10.f]];

_barChartView.leftAxis.startAtZeroEnabled = NO;

_barChartView.data = data;

Solution

  • The below solved my problem.

    leftAxis.labelCount = 5;
    leftAxis.forceLabelsEnabled = YES;