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

Line Chart Dynamic Updating #951

Closed
asdfasdf126 opened this issue Apr 15, 2016 · 1 comment
Closed

Line Chart Dynamic Updating #951

asdfasdf126 opened this issue Apr 15, 2016 · 1 comment

Comments

@asdfasdf126
Copy link

I am trying to create a line graph that updates as it gets points. The problem I'm having is the graph will not update unless i am interacting with it. Either moving the graph or even tapping it. I'm out of ideas on how to remedy this problem and i have not been able to find anything that comes close to working.

LineChartData *data = self.chartView.data;

if(data != nil)
{
    LineChartDataSet *set = [data getDataSetByIndex:0];

    if(set == nil)
    {
        set = [[LineChartDataSet alloc] init];

        set.drawCirclesEnabled = false;
        set.drawValuesEnabled = false;
        [set setColor:UIColor.blackColor];
        set.lineWidth = 1.0;
        set.valueFont = [UIFont systemFontOfSize:9.f];
        set.drawCubicEnabled = true;

        NSArray *gradientColors = @[
                                    (id)[ChartColorTemplates colorFromString:@"#00ff0000"].CGColor,
                                    (id)[ChartColorTemplates colorFromString:@"#ffff0000"].CGColor
                                    ];
        CGGradientRef gradient = CGGradientCreateWithColors(nil, (CFArrayRef)gradientColors, nil);

        set.fillAlpha = 1.f;
        set.fill = [ChartFill fillWithLinearGradient:gradient angle:90.f];
        set.drawFilledEnabled = true;

        CGGradientRelease(gradient);

        [data addDataSet:set];
    }

    [self.chartView setVisibleXRangeMaximum:MAXVALUES];
    [self.chartView setVisibleXRangeMinimum:MAXVALUES];

    [data addXValue:[NSString stringWithFormat:@"%.f", xVal]];
    [data addEntry:[[ChartDataEntry alloc] initWithValue:yVal xIndex:xVal] dataSetIndex:0];

    int move = [[set entryForIndex:[set entryCount] - 1] xIndex];

    [self.chartView notifyDataSetChanged];
    [self.chartView moveViewToX:(move - MAXVALUES < 0)?0:move - MAXVALUES];
}
else
    self.chartView.data = [[LineChartData alloc] init];
@liuxuan30
Copy link
Member

just search 'Dynamic' in issues, you will see some options.

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