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

Cubic line charts don't get filled correctly if data doesn't start at index 0 #711

Closed
gunterhager opened this issue Jan 26, 2016 · 0 comments

Comments

@gunterhager
Copy link
Contributor

If you set up your data entries for the cubic line chart so that they don't start at x-index 0, the fill is still drawn from x-index 0.

Set up data entries like this:

[[ChartDataEntry alloc] initWithValue:val xIndex:i + offset]

The chart will look like this:
screen shot 2016-01-26 at 09 21 01

This happens only with cubic line charts. Regular line charts are rendered like this:
screen shot 2016-01-26 at 09 22 06

You can easily reproduce the bug by replacing the setDataCount:range: method in CubicLineChartViewController.m in the demo with:

- (void)setDataCount:(int)count range:(double)range
{
    NSMutableArray *xVals = [[NSMutableArray alloc] init];

    for (int i = 0; i < count; i++)
    {
        [xVals addObject:[@(i + 1990) stringValue]];
    }

    NSMutableArray *yVals1 = [[NSMutableArray alloc] init];

    int offset = 10;

    for (int i = 0; i < count - offset; i++)
    {
        double mult = (range + 1);
        double val = (double) (arc4random_uniform(mult)) + 20;
        [yVals1 addObject:[[ChartDataEntry alloc] initWithValue:val xIndex:i + offset]];
    }

    LineChartDataSet *set1 = [[LineChartDataSet alloc] initWithYVals:yVals1 label:@"DataSet 1"];
    set1.drawCubicEnabled = YES;
    set1.cubicIntensity = 0.2;
    set1.drawCirclesEnabled = NO;
    set1.lineWidth = 1.8;
    set1.circleRadius = 4.0;
    [set1 setCircleColor:UIColor.whiteColor];
    set1.highlightColor = [UIColor colorWithRed:244/255.f green:117/255.f blue:117/255.f alpha:1.f];
    [set1 setColor:UIColor.whiteColor];
    set1.fillColor = UIColor.whiteColor;
    set1.fillAlpha = 0.5f;
    set1.drawFilledEnabled = YES;
    set1.drawHorizontalHighlightIndicatorEnabled = NO;
    set1.fillFormatter = [[CubicLineSampleFillFormatter alloc] init];

    LineChartData *data = [[LineChartData alloc] initWithXVals:xVals dataSet:set1];
    [data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:9.f]];
    [data setDrawValues:NO];

    _chartView.data = data;
}
gunterhager pushed a commit to gunterhager/ios-charts that referenced this issue Jan 26, 2016
…t x-index 0 (ChartsOrg#711)

Cubic line charts that don’t start at x-index 0 don’t fill correctly
because the fill starts at index 0 (Regular line charts don’t have that
issue). To correct this the index for the fill is taken from the data
entries (similar to regular line chart fill).
Ultimately i think the renderer should be refactored to use a common
code path for filling cubic and regular line charts.
danielgindi added a commit that referenced this issue Feb 23, 2016
Fix for cubic line chart fill when charts that don't start at x-index 0 #711
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