BEMSimpleLineGraph
BEMSimpleLineGraph copied to clipboard
Strange drawing result
Hi, I'm new to this library. I'm trying to get a partial graph. The result is almost right - except for the white triangle where the the partial line ends. My code is very basic: total 8 points, two of them have data and others are left out
- (NSInteger)numberOfPointsInLineGraph:(BEMSimpleLineGraphView *)graph {
NSIndexPath *indexPath = graphLinks[graph];
NSDictionary *indicator = [self findIndicator:indexPath];
NSArray *values = indicator[@"graphData"][@"labels"];
return values.count;
}
- (CGFloat)lineGraph:(BEMSimpleLineGraphView *)graph valueForPointAtIndex:(NSInteger)index {
NSIndexPath *indexPath = graphLinks[graph];
NSDictionary *indicator = [self findIndicator:indexPath];
NSArray *values = indicator[@"graphData"][@"values"];
if (values.count > index) {
return [values[index] floatValue];
} else
return BEMNullGraphValue;
}

The culprit seems to be the bottomPointsArray method. My workaround below:
- (NSArray *)bottomPointsArray {
CGPoint bottomPointZero = CGPointMake(0, self.frame.size.height);
CGPoint bottomPointFull = CGPointMake(self.frame.size.width, self.frame.size.height);
NSMutableArray *bottomPoints = [NSMutableArray arrayWithArray:self.points];
[bottomPoints insertObject:[NSValue valueWithCGPoint:bottomPointZero] atIndex:0];
// add one point to complete the polygon
CGPoint oneMore = CGPointMake(self.frame.size.width, 0);
[bottomPoints addObject:[NSValue valueWithCGPoint:oneMore]];
[bottomPoints addObject:[NSValue valueWithCGPoint:bottomPointFull]];
return bottomPoints;
}
I needed to change the visuals so now my code looks like this
- (NSArray *)bottomPointsArray {
CGPoint bottomPointZero = CGPointMake(0, self.frame.size.height);
// CGPoint bottomPointFull = CGPointMake(self.frame.size.width, self.frame.size.height);
CGPoint bottomPointFull = [self.points.lastObject CGPointValue];
bottomPointFull.y = self.frame.size.height;
NSMutableArray *bottomPoints = [NSMutableArray arrayWithArray:self.points];
[bottomPoints insertObject:[NSValue valueWithCGPoint:bottomPointZero] atIndex:0];
[bottomPoints addObject:[NSValue valueWithCGPoint:bottomPointFull]];
return bottomPoints;
}
