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

Grouped Bar chart X-axis and Bar Alignment #2832

Closed
sharatkannan opened this issue Sep 28, 2017 · 3 comments
Closed

Grouped Bar chart X-axis and Bar Alignment #2832

sharatkannan opened this issue Sep 28, 2017 · 3 comments

Comments

@sharatkannan
Copy link

sharatkannan commented Sep 28, 2017

In the demo chart application,Combined graph bar chart end bar not fully showing.
Demo bar chart data like this.

  • I only need grouped bar chart.
  • This alignment issue also in bar chart example.

Setting Grouped Barchart:

- (BarChartData *)generateBarData
{
    NSMutableArray<BarChartDataEntry *> *entries1 = [[NSMutableArray alloc] init];
    NSMutableArray<BarChartDataEntry *> *entries2 = [[NSMutableArray alloc] init];
    
    for (int index = 0; index < ITEM_COUNT; index++)
    {
        [entries1 addObject:[[BarChartDataEntry alloc] initWithX:index y:(arc4random_uniform(25) + 25)]];
        
        // stacked
        [entries2 addObject:[[BarChartDataEntry alloc] initWithX:index   yValues:@[@(arc4random_uniform(13) + 12), @(arc4random_uniform(13) + 12)]]];
        
    }

    BarChartDataSet *set1 = [[BarChartDataSet alloc] initWithValues:entries1 label:@"Bar 1"];
    [set1 setColor:[UIColor colorWithRed:60/255.f green:220/255.f blue:78/255.f alpha:1.f]];
    set1.valueTextColor = [UIColor colorWithRed:60/255.f green:220/255.f blue:78/255.f alpha:1.f];
    set1.valueFont = [UIFont systemFontOfSize:10.f];
    set1.axisDependency = AxisDependencyLeft;
    
    BarChartDataSet *set2 = [[BarChartDataSet alloc] initWithValues:entries2 label:@""];
    set2.stackLabels = @[@"Stack 1", @"Stack 2"];
    set2.colors = @[
                    [UIColor colorWithRed:61/255.f green:165/255.f blue:255/255.f alpha:1.f],
                    [UIColor colorWithRed:23/255.f green:197/255.f blue:255/255.f alpha:1.f]
                    ];
    set2.valueTextColor = [UIColor colorWithRed:61/255.f green:165/255.f blue:255/255.f alpha:1.f];
    set2.valueFont = [UIFont systemFontOfSize:10.f];
    set2.axisDependency = AxisDependencyLeft;

    float groupSpace = 0.06f;
    float barSpace = 0.02f; // x2 dataset
    float barWidth = 0.45f; // x2 dataset
    // (0.45 + 0.02) * 2 + 0.06 = 1.00 -> interval per "group"
    
    
    BarChartData *d = [[BarChartData alloc] initWithDataSets:@[set1, set2]];
    
    d.barWidth = barWidth;
    
    // make this BarData object grouped
    [d groupBarsFromX:0.0 groupSpace:groupSpace barSpace:barSpace]; // start at x = 0
    
    return d;
}

But getting result like:
simulator screen shot 28-sep-2017 10 21 36 am

The last bar not showing.
I changed the bar width. in that time changing the x alignment. X - Axis are not aligned to the bars.
simulator screen shot 28-sep-2017 10 20 57 am

@sharatkannan sharatkannan changed the title Grouped Bar chart X-axis and Bar Chart Alignment Grouped Bar chart X-axis and Bar Alignment Sep 28, 2017
@roxanajula
Copy link

Have you tried setting the chartView.xAxis.centerAxisLabelsEnabled = true ?

@sharatkannan
Copy link
Author

yes. I set centerAxisLabelsEnabled as true.

@liuxuan30
Copy link
Member

liuxuan30 commented Oct 25, 2017

have you updated the library code to latest, or do you change scale? I am not sure why but on my side, combined chart looks fine

One important thing is, if you just delete other parts and only take grouped bar charts in a combined chart, you will get it wrong because they are different. You should only use BarChartView if you only have bar charts.

image

changing center axis label is fine(you may argue Jan column includes both Jan and Feb, it's formatter issue, not the alignment issue)
image

Note Feb is missing, but if you zoom in:
image

So it looks like the tail has been cut off, but it's expected because we zoomed in.

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

3 participants