Currently i'm using iosChart in my project. I have used the bar chart in shown below in image:
The problem is It is not showing(2nd and 4th) entire x - axis lable. when I zoom then showing. Is there any way to show this lable?
Here is my code:
chartView.delegate = self;
chartView.descriptionText = @"";
chartView.noDataTextDescription = GGLocalizeString(@"deshboard.ui.chart.empty");
chartView.drawBarShadowEnabled = NO;
chartView.drawValueAboveBarEnabled = YES;
chartView.maxVisibleValueCount = 60;
chartView.pinchZoomEnabled = NO;
chartView.drawGridBackgroundEnabled = NO;
ChartXAxis *xAxis = chartView.xAxis;
xAxis.labelPosition = XAxisLabelPositionBottom;
xAxis.labelFont = [UIFont systemFontOfSize:10.f];
xAxis.drawGridLinesEnabled = NO;
xAxis.spaceBetweenLabels = 2.0;
ChartYAxis *leftAxis = chartView.leftAxis;
leftAxis.labelFont = [UIFont systemFontOfSize:10.f];
leftAxis.labelCount = 8;
leftAxis.valueFormatter = [[NSNumberFormatter alloc] init];
leftAxis.valueFormatter.maximumFractionDigits = 1;
leftAxis.valueFormatter.negativeSuffix = @"";
leftAxis.valueFormatter.positiveSuffix = @"";
leftAxis.labelPosition = YAxisLabelPositionOutsideChart;
leftAxis.spaceTop = 0.15;
ChartYAxis *rightAxis = chartView.rightAxis;
rightAxis.drawGridLinesEnabled = NO;
rightAxis.labelFont = [UIFont systemFontOfSize:10.f];
rightAxis.labelCount = 8;
rightAxis.valueFormatter = leftAxis.valueFormatter;
rightAxis.spaceTop = 0.15;
chartView.legend.position = ChartLegendPositionBelowChartLeft;
chartView.legend.form = ChartLegendFormSquare;
chartView.legend.formSize = 9.0;
chartView.legend.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:11.f];
chartView.legend.xEntrySpace = 4.0;
if (self.chartData.arrayCityData.count == 0) {
return cell;
}
//X - VALUE
NSMutableArray *xVals = [[NSMutableArray alloc] init];
for (int i = 0; i < [self.chartData.arrayCityData count]; i++)
{
DealData *dealData = [self.chartData.arrayCityData objectAtIndex:i];
[xVals addObject: [NSString stringWithFormat:@"%@(%.2f%%)",dealData.name,[dealData.totalClick floatValue]*100/[self totalCityClicks]]];
}
//Y - VALUE
NSMutableArray *yVals = [[NSMutableArray alloc] init];
for (int i = 0; i < [self.chartData.arrayCityData count]; i++)
{
DealData *dealData = [self.chartData.arrayCityData objectAtIndex:i];
[yVals addObject:[[BarChartDataEntry alloc] initWithValue:[dealData.totalClick doubleValue] xIndex:i]];
}
BarChartDataSet *set1 = [[BarChartDataSet alloc] initWithYVals:yVals label:GGLocalizeString(@"deshboard.ui.cell.lblTitle6.cities")];
set1.barSpace = 0.35;
NSMutableArray *dataSets = [[NSMutableArray alloc] init];
[dataSets addObject:set1];
BarChartData *data = [[BarChartData alloc] initWithXVals:xVals dataSets:dataSets];
[data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:10.f]];
//remove decimal
NSNumberFormatter *vf = [[NSNumberFormatter alloc] init];
vf.generatesDecimalNumbers = NO;
data.valueFormatter = vf;
chartView.data = data;
chartView.legend.position = ChartLegendPositionBelowChartLeft;
chartView.legend.form = ChartLegendFormSquare;
chartView.legend.formSize = 9.0;
chartView.legend.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:11.f];
chartView.legend.xEntrySpace = 4.0;
if (self.chartData.arrayCityData.count == 0) {
return cell;
}
//X - VALUE
NSMutableArray *xVals = [[NSMutableArray alloc] init];
for (int i = 0; i < [self.chartData.arrayCityData count]; i++)
{
DealData *dealData = [self.chartData.arrayCityData objectAtIndex:i];
[xVals addObject: [NSString stringWithFormat:@"%@(%.2f%%)",dealData.name,[dealData.totalClick floatValue]*100/[self totalCityClicks]]];
}
//Y - VALUE
NSMutableArray *yVals = [[NSMutableArray alloc] init];
for (int i = 0; i < [self.chartData.arrayCityData count]; i++)
{
DealData *dealData = [self.chartData.arrayCityData objectAtIndex:i];
[yVals addObject:[[BarChartDataEntry alloc] initWithValue:[dealData.totalClick doubleValue] xIndex:i]];
}
BarChartDataSet *set1 = [[BarChartDataSet alloc] initWithYVals:yVals label:GGLocalizeString(@"deshboard.ui.cell.lblTitle6.cities")];
set1.barSpace = 0.35;
NSMutableArray *dataSets = [[NSMutableArray alloc] init];
[dataSets addObject:set1];
BarChartData *data = [[BarChartData alloc] initWithXVals:xVals dataSets:dataSets];
[data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:10.f]];
//remove decimal
NSNumberFormatter *vf = [[NSNumberFormatter alloc] init];
vf.generatesDecimalNumbers = NO;
data.valueFormatter = vf;
chartView.data = data;
well, by default, ios-charts will calculate a modulus for x axis to decide the interval to draw the x axis labels. that's your case. because every label is longer than the bar, so to avoid the label overlap, we have to do it.
If you don't want so, just call xAxis.setLabelsToSkip(0)