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

How to draw a LineChartDataSet skipping certain data points #622

Closed
dddppp opened this issue Dec 21, 2015 · 1 comment
Closed

How to draw a LineChartDataSet skipping certain data points #622

dddppp opened this issue Dec 21, 2015 · 1 comment

Comments

@dddppp
Copy link

dddppp commented Dec 21, 2015

Hello,

below there is the method that I use to generateLineData. However I would like to skip the data points where the data.price value is different than INT16_MIN.

Unfortunately there is no source code for " [[LineChartDataSet alloc] initWithYVals:entries label:@"Price"];". The code below does not seem to do the job as I believe passing a mutable array to the initWithYVals method is not the correct way to deal with this (there is no fixed enumeration on it so it would not know when a data point is missed).

What should I do to get the library to skip some data points?

- (LineChartData *)generateLineData
    {
    LineChartData *d = [[LineChartData alloc] init];

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

    for (int index = 0; index < [self.data count]; index++)
    {
        MyData * data = [self.data objectAtIndex:index];
        if (data.price != INT16_MIN) {
            [entries addObject:[[ChartDataEntry alloc] initWithValue:data.price xIndex:index]];
        }
    }

    LineChartDataSet *set = [[LineChartDataSet alloc] initWithYVals:entries label:@"Price"];
    [set setColor:[UIColor colorWithRed:240/255.f green:238/255.f blue:70/255.f alpha:1.f]];
    //    set.lineWidth = 2.5;
    set.lineWidth = 1.0;
    [set setCircleRadius:1.0f];
    [set setCircleColor:[UIColor colorWithRed:240/255.f green:238/255.f blue:70/255.f alpha:1.f]];
    set.fillColor = [UIColor colorWithRed:240/255.f green:238/255.f blue:70/255.f alpha:1.f];
    set.drawCubicEnabled = YES;
    set.drawValuesEnabled = YES;
    set.valueFont = [UIFont systemFontOfSize:0.f];
    set.valueTextColor = [UIColor colorWithRed:240/255.f green:238/255.f blue:70/255.f alpha:1.f];
    // set.axisDependency = AxisDependencyLeft;

    [d addDataSet:set];
    return d;
}
@liuxuan30
Copy link
Member

you can just don't feed y value for the specific xIndex. It will pass it, and then connect the previous data to the next valid one.
e.g.
x: 0 1 2 3 4
y: 1 _ 3 5 6
it will connect 1 3 5 6

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