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

xAxis labels are not aligned with grouped bar, when data is more #3364

Closed
Arunarak opened this issue Mar 26, 2018 · 2 comments
Closed

xAxis labels are not aligned with grouped bar, when data is more #3364

Arunarak opened this issue Mar 26, 2018 · 2 comments

Comments

@Arunarak
Copy link

Hi,

I have an issue, xAxis label are not aligned to grouped bar graph when data is more. some labels are missing and everything seems to be fine when zoomed in.
here is my code

chartView.descriptionText =@"";//dic[kJSONChartTitleKey];
// chartView.noDataTextDescription = @"No available data for the chart.";
[chartView setHighlightPerDragEnabled:NO];
chartView.drawBarShadowEnabled = NO;
chartView.drawValueAboveBarEnabled = YES;
chartView.dragEnabled = YES;
// [chartView setScaleEnabled:YES];
// [chartView setScaleXEnabled:YES];
[chartView setScaleYEnabled:YES];
[chartView setDoubleTapToZoomEnabled:YES];
chartView.pinchZoomEnabled = YES;
chartView.drawGridBackgroundEnabled = NO;
chartView.drawBordersEnabled = NO;
chartView.maxVisibleCount = 200;
chartView.fitBars = YES;

        chartView.autoScaleMinMaxEnabled = YES ;
        [chartView setScaleXEnabled:YES];
      
     //   [chartView zoomWithScaleX:5 scaleY:5 x:0.0 y:0.0] ;
        [chartView fitScreen];

ChartXAxis *xAxis = chartView.xAxis;
[xAxis setLabelPosition:XAxisLabelPositionBottom];
xAxis.labelFont = [UIFont systemFontOfSize:10.f];
xAxis.labelTextColor = [UIColor darkGrayColor];
xAxis.drawAxisLineEnabled = YES;
xAxis.drawGridLinesEnabled = NO;
xAxis.drawLimitLinesBehindDataEnabled = YES;

        xAxis.gridLineWidth = .0;
        xAxis.wordWrapEnabled = YES;
        [xAxis setLabelWidth:1.0];
        [xAxis setWordWrapEnabled:YES];
        [xAxis setWordWrapWidthPercent:2.0];
        xAxis.granularityEnabled = true ;
        xAxis.granularity =  1;
       
        xAxis.avoidFirstLastClippingEnabled = YES;
        xAxis.labelCount = labelArray.count;
        xAxis.labelHeight = 3.0;
        xAxis.centerAxisLabelsEnabled = YES;
        xAxis.labelPosition = XAxisLabelPositionBottom ;

        
 
       chartView.xAxis.axisMinimum =  0.0 ;
  
       chartView.xAxis.axisMaximum = self.dataArray.count  ;

NSMutableArray *xVals = [[NSMutableArray alloc] initWithCapacity:labelsArray.count];

        for (int i = 0; i < labelsArray.count; i++){
            [xVals addObject:labelsArray[i % labelsArray.count]];
        }
        
        NSLog(@" xvals %@", xVals) ;
        
        
        
        xAxis.labelCount = labelsArray.count  ;
        
        IntAxisValueFormatter *format = [[IntAxisValueFormatter alloc]init];
        format.xAxisValues = xVals;
        
        
        NSArray * values = [NSArray array];
        
        if (labelsArray.count) {
            values = [NSArray arrayWithArray:priorArray];
        }
        NSArray * currentValues = [NSArray array];
        
        if (labelsArray.count) {
            currentValues = [NSArray arrayWithArray:currentArray];
        }
        
        NSMutableArray *yVals = [[NSMutableArray alloc] initWithCapacity:values.count];
        NSMutableArray *yCurrentVals = [[NSMutableArray alloc] initWithCapacity:currentValues.count];
        
        for (int i = 0; i < values.count; i++)
        {
            NSInteger val1 = [values[i] integerValue];
            [yVals addObject:[[BarChartDataEntry alloc]initWithX:i  y:val1]];
            NSInteger val = [currentValues[i] integerValue];
            
            [yCurrentVals addObject:[[BarChartDataEntry alloc]initWithX:i  y:val]];

        }
             chartView.xAxis.valueFormatter = format;

    
        BarChartDataSet *set1 ;
        BarChartDataSet *set2 ;
        
      NSMutableArray *dataSets = [[NSMutableArray alloc] init];
        [dataSets addObject:set1];
        [dataSets addObject:set2];
        
        BarChartData *data = [[BarChartData alloc] initWithDataSets:dataSets];

        float groupSpace = 0.3;
        float barSpace = 0.05;
        data.barWidth = 0.3;
        [data groupBarsFromX:0 groupSpace:groupSpace barSpace:barSpace];
   
        chartView.data = data;

I have screenshot too.

  1. screen shot 2018-03-26 at 5 22 46 pm
  2. screen shot 2018-03-26 at 5 22 30 pm

The first picture is proper and the dataarray is 10.
the second picture doesn't show xAxis label and the data array size is 50+.but if zoom in we could see all the labels.

Please help.

Thank You.

@Arunarak
Copy link
Author

@danielgindi

@liuxuan30
Copy link
Member

take a look at Chart demos. seems you didn't group bars correctly. the grouped bars width and space sum must be 1.0

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