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

[BUG] Bar Chart incorrect rendering for special data #214

Closed
liuxuan30 opened this issue Jul 15, 2015 · 3 comments
Closed

[BUG] Bar Chart incorrect rendering for special data #214

liuxuan30 opened this issue Jul 15, 2015 · 3 comments

Comments

@liuxuan30
Copy link
Member

Here's what I changed in - (void)setDataCount:(int)count range:(double)range for the demo multiple bar chart view controller, other remains the same:

- (void)setDataCount:(int)count range:(double)range
{
    NSMutableArray *xVals = [[NSMutableArray alloc] init];
    for (int i = 0; i < 11; i++)
    {
        [xVals addObject:[@(i + 2015) stringValue]];
    }
    NSMutableArray *yVals1 = [[NSMutableArray alloc] init];
    NSMutableArray *yVals2 = [[NSMutableArray alloc] init];

    for (int i = 0; i < 11; i++)
    {
        if (i == 0) {
            [yVals1 addObject:[[BarChartDataEntry alloc] initWithValue:2354235 xIndex:i]];
            [yVals2 addObject:[[BarChartDataEntry alloc] initWithValue:3354235 xIndex:i]];
        } else if (i == 10) {
            [yVals1 addObject:[[BarChartDataEntry alloc] initWithValue:6354235 xIndex:i]];
            [yVals2 addObject:[[BarChartDataEntry alloc] initWithValue:7354235 xIndex:i]];
        } else {
            continue;
        }
    }

    BarChartDataSet *set1 = [[BarChartDataSet alloc] initWithYVals:yVals1 label:@"Company A"];
    [set1 setColor:[UIColor colorWithRed:104/255.f green:241/255.f blue:175/255.f alpha:1.f]];
    BarChartDataSet *set2 = [[BarChartDataSet alloc] initWithYVals:yVals2 label:@"Company B"];
    [set2 setColor:[UIColor colorWithRed:164/255.f green:228/255.f blue:251/255.f alpha:1.f]];

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

    BarChartData *data = [[BarChartData alloc] initWithXVals:xVals dataSets:dataSets];
    data.groupSpace = 0.8;
    [data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:10.f]];
    _chartView.leftAxis.startAtZeroEnabled = NO;
    _chartView.rightAxis.startAtZeroEnabled = NO;
    _chartView.data = data;
}

It render the second group of bars at xIndex:10 in a wrong postion. The correct postion should be at the right most position, since the second group is at xIndex 10 as the last data entry.
2015

@liuxuan30
Copy link
Member Author

I was told not to insert nil/NAN value at specific xIndex. So my data only has value at xIndex:0 and xIndex:10. However, the _deltaX is using entryCount to calculate, and it goes wrong.

I found at least two functions is using entryCount: BarChartView->calMinMax() and BarChartViewRenderer->drawDataSets()

I have to temporarily choose to insert nan into the dataSet, and handle the nan situation myself (it crashes from time to time if no nan check).

the mis-rendered bars cannot be highlighted by touch.

I think it's a serious bug @danielgindi

@liuxuan30
Copy link
Member Author

Tried one fix #221 for bar chart. Other bar-like chart not touched yet, as I need @danielgindi to confirm if my fix is correct. Then we can take a look at other bar-like charts.

@ghizoulo
Copy link

I am using v3.0.1 but still have the same problem. the bars are misplaced. Please if u can help me with that check #3154

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