diff --git a/Classes/JBBarChartView.h b/Classes/JBBarChartView.h index b8620ef99..37a25a142 100644 --- a/Classes/JBBarChartView.h +++ b/Classes/JBBarChartView.h @@ -14,8 +14,8 @@ @interface JBBarChartView : JBChartView -@property (nonatomic, weak) id delegate; -@property (nonatomic, weak) id dataSource; +@property (nonatomic, weak) IBOutlet id delegate; +@property (nonatomic, weak) IBOutlet id dataSource; /** * Vertical highlight overlayed on bar during touch events. diff --git a/Classes/JBLineChartView.h b/Classes/JBLineChartView.h old mode 100755 new mode 100644 index 2828a2ef9..9aed87603 --- a/Classes/JBLineChartView.h +++ b/Classes/JBLineChartView.h @@ -27,8 +27,8 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){ @interface JBLineChartView : JBChartView -@property (nonatomic, weak) id delegate; -@property (nonatomic, weak) id dataSource; +@property (nonatomic, weak) IBOutlet id delegate; +@property (nonatomic, weak) IBOutlet id dataSource; /** * Vertical highlight overlayed on a line graph during touch events. @@ -46,6 +46,23 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){ */ @property (nonatomic, assign) BOOL showsLineSelection; +/** + * A highlight shown on a area under a line within the graph during touch events. The highlighted area + * is the on under the closest line to the touch point and corresponds to the lineIndex delegatd back via + * didSelectChartAtHorizontalIndex:atLineIndex: and didUnSlectChartAtHorizontalIndex:atLineIndex: + * + * Default: NO. + */ +@property (nonatomic, assign) BOOL showsAreaSelection; + +/** + * If YES the chart adds the value of the next line to the previous. The distance of a line to the one below + * represents the upper lines real value. For best results you should also set the BOOL fillsAreaBelowLine to YES + * + * Default: NO. + */ +@property (nonatomic, assign) BOOL isCumulative; + @end @protocol JBLineChartViewDelegate @@ -260,4 +277,16 @@ typedef NS_ENUM(NSInteger, JBLineChartViewLineStyle){ */ - (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NSUInteger)lineIndex; +/** + * Returns whether or not the area under the line should be filled + * + * Default: NO + * + * @param lineChartView The line chart object requesting this information. + * @param lineIndex An index number identifying a line in the chart. + * + * @return Whether or not the area under the line should be filled + */ +- (BOOL)lineChartView:(JBLineChartView *)lineChartView fillsAreaUnderLineWithIndex:(NSUInteger)lineIndex; + @end diff --git a/Classes/JBLineChartView.m b/Classes/JBLineChartView.m old mode 100755 new mode 100644 index 7be13588f..bcc627ba3 --- a/Classes/JBLineChartView.m +++ b/Classes/JBLineChartView.m @@ -57,6 +57,10 @@ @interface JBLineLayer : CAShapeLayer @end +@interface JBAreaLayer : JBLineLayer + +@end + @interface JBLineChartPoint : NSObject @property (nonatomic, assign) CGPoint position; @@ -82,6 +86,7 @@ - (void)fireCallback:(void (^)())callback; // View helpers - (JBLineLayer *)lineLayerForLineIndex:(NSUInteger)lineIndex; +- (JBAreaLayer *)areaLayerForLineIndex:(NSUInteger)lineIndex; @end @@ -94,6 +99,7 @@ - (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView widthFo - (CGFloat)paddingForLineChartLinesView:(JBLineChartLinesView *)lineChartLinesView; - (JBLineChartViewLineStyle)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex; - (BOOL)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView smoothLineAtLineIndex:(NSUInteger)lineIndex; +- (BOOL)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillsAreaUnderLineWithIndex:(NSUInteger)lineIndex; @end @@ -133,6 +139,7 @@ - (id)initWithRadius:(CGFloat)radius; @end + @interface JBLineChartView () @property (nonatomic, strong) NSArray *chartData; @@ -217,6 +224,8 @@ - (void)construct { _showsVerticalSelection = YES; _showsLineSelection = YES; + _showsAreaSelection = NO; + _isCumulative = NO; _cachedMinHeight = kJBBarChartViewUndefinedCachedHeight; _cachedMaxHeight = kJBBarChartViewUndefinedCachedHeight; } @@ -261,8 +270,20 @@ - (void)reloadData NSAssert(rawHeight >= 0, @"JBLineChartView // delegate function - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex must return a CGFloat >= 0"); CGFloat normalizedHeight = [self normalizedHeightForRawHeight:rawHeight]; - yOffset = mainViewRect.size.height - normalizedHeight; - + + //TODO: heigt of line below if no point direct below + if (_isCumulative) { + CGFloat normalizedHeightOfLineBelow = mainViewRect.size.height; + if (lineIndex > 0) { + CGFloat rawHeightOfLineBelow = [self.delegate lineChartView:self verticalValueForHorizontalIndex:horizontalIndex atLineIndex:lineIndex - 1]; + normalizedHeightOfLineBelow -= [self normalizedHeightForRawHeight:rawHeightOfLineBelow]; + } + + yOffset = normalizedHeightOfLineBelow - normalizedHeight; + } else { + yOffset = mainViewRect.size.height - normalizedHeight; + } + JBLineChartPoint *chartPoint = [[JBLineChartPoint alloc] init]; chartPoint.position = CGPointMake(xOffset, yOffset); @@ -328,6 +349,7 @@ - (void)reloadData [self addSubview:self.dotsView]; } }; + /* * Creates a vertical selection view for touch events @@ -606,6 +628,15 @@ - (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView showsDotsForL return NO; } +- (BOOL)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView fillsAreaUnderLineWithIndex:(NSUInteger)lineIndex +{ + if ([self.dataSource respondsToSelector:@selector(lineChartView:fillsAreaUnderLineWithIndex:)]) { + return [self.dataSource lineChartView:self fillsAreaUnderLineWithIndex:lineIndex]; + } + return NO; +} + + #pragma mark - Setters - (void)setState:(JBChartViewState)state animated:(BOOL)animated callback:(void (^)())callback force:(BOOL)force @@ -703,21 +734,45 @@ - (CGFloat)cachedMaxHeight if (_cachedMaxHeight == kJBBarChartViewUndefinedCachedHeight) { CGFloat maxHeight = 0; - NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView"); - for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++) - { - NSAssert([self.dataSource respondsToSelector:@selector(lineChartView:numberOfVerticalValuesAtLineIndex:)], @"JBLineChartView // dataSource must implement - (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex"); - NSUInteger dataCount = [self.dataSource lineChartView:self numberOfVerticalValuesAtLineIndex:lineIndex]; - for (NSUInteger horizontalIndex=0; horizontalIndex= 0, @"JBLineChartView // delegate function - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex must return a CGFloat >= 0"); - if (height > maxHeight) + NSAssert([self.dataSource respondsToSelector:@selector(lineChartView:numberOfVerticalValuesAtLineIndex:)], @"JBLineChartView // dataSource must implement - (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex"); + NSUInteger dataCount = [self.dataSource lineChartView:self numberOfVerticalValuesAtLineIndex:lineIndex]; + for (NSUInteger horizontalIndex=0; horizontalIndex= 0, @"JBLineChartView // delegate function - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex must return a CGFloat >= 0"); + if (height > maxHeight) + { + maxHeight = height; + } + } } + } else { + NSAssert([self.dataSource respondsToSelector:@selector(numberOfLinesInLineChartView:)], @"JBLineChartView // dataSource must implement - (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView"); + for (NSUInteger lineIndex=0; lineIndex<[self.dataSource numberOfLinesInLineChartView:self]; lineIndex++) + { + CGFloat maxHeightInLine = 0; + NSAssert([self.dataSource respondsToSelector:@selector(lineChartView:numberOfVerticalValuesAtLineIndex:)], @"JBLineChartView // dataSource must implement - (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex"); + NSUInteger dataCount = [self.dataSource lineChartView:self numberOfVerticalValuesAtLineIndex:lineIndex]; + for (NSUInteger horizontalIndex=0; horizontalIndex= 0, @"JBLineChartView // delegate function - (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex must return a CGFloat >= 0"); + if (height > maxHeightInLine) + { + maxHeightInLine = height; + } + } + maxHeight += maxHeightInLine; + } + } _cachedMaxHeight = maxHeight; } @@ -991,6 +1046,20 @@ - (void)setLineStyle:(JBLineChartViewLineStyle)lineStyle @end + +@implementation JBAreaLayer + +-(id)init +{ + self = [super init]; + if (self) { + self.strokeColor = [UIColor clearColor].CGColor; + } + return self; +} + +@end + @implementation JBLineChartPoint #pragma mark - Alloc/Init @@ -1048,9 +1117,11 @@ - (void)drawRect:(CGRect)rect CGFloat padding = [self.delegate paddingForLineChartLinesView:self]; NSUInteger lineIndex = 0; + NSInteger fillingBottomLineIndex = -1; //-1 is x-axis for (NSArray *lineData in chartData) { UIBezierPath *path = [UIBezierPath bezierPath]; + UIBezierPath *fillingPath = [UIBezierPath bezierPath]; path.miterLimit = kJBLineChartLinesViewMiterLimit; JBLineChartPoint *previousLineChartPoint = nil; @@ -1102,36 +1173,123 @@ - (void)drawRect:(CGRect)rect previousLineChartPoint = lineChartPoint; index++; } + + + NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:fillsAreaUnderLineWithIndex:)], @"JBLineChartLinesView // delegate must implement - (BOOL)lineChartLineView:(JBLineChartLinesView *)lineChartLinesView fillsAreaUnderLineWithIndex:(NSUInteger)lineIndex"); + BOOL fillAreUnderLine = [self.delegate lineChartLinesView:self fillsAreaUnderLineWithIndex:lineIndex]; + if (fillAreUnderLine) { + NSArray *bottomLineData = nil; + if (fillingBottomLineIndex == -1) { + //x-axis is bottom line + JBLineChartPoint *lowerRightCornor = [[JBLineChartPoint alloc] init]; + lowerRightCornor.position = CGPointMake(self.bounds.size.width - padding, self.bounds.size.height - padding); + JBLineChartPoint *lowerLeftCornor = [[JBLineChartPoint alloc] init]; + lowerLeftCornor.position = CGPointMake(padding, self.bounds.size.height); + bottomLineData = @[lowerLeftCornor, lowerRightCornor]; + } else { + bottomLineData = chartData[fillingBottomLineIndex]; + } + + //FIXME: I don't know how to avoid this code copy. + previousSlope = 0; + NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:smoothLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (BOOL)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView smoothLineAtLineIndex:(NSUInteger)lineIndex"); + BOOL smoothBottomLine = fillingBottomLineIndex == -1 ? NO : [self.delegate lineChartLinesView:self smoothLineAtLineIndex:fillingBottomLineIndex]; + NSArray *inversedLineData = [[bottomLineData reverseObjectEnumerator] allObjects]; + NSArray *fillingLineData = [sortedLineData arrayByAddingObjectsFromArray:inversedLineData]; + NSUInteger index = 0; + for (JBLineChartPoint *lineChartPoint in fillingLineData) + { + if (index == 0) + { + [fillingPath moveToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)))]; + } + else + { + JBLineChartPoint *nextLineChartPoint = nil; + if (index != ([fillingLineData count] - 1)) + { + nextLineChartPoint = [fillingLineData objectAtIndex:(index + 1)]; + } + + CGFloat nextSlope = (nextLineChartPoint != nil) ? ((nextLineChartPoint.position.y - lineChartPoint.position.y)) / ((nextLineChartPoint.position.x - lineChartPoint.position.x)) : previousSlope; + CGFloat currentSlope = ((lineChartPoint.position.y - previousLineChartPoint.position.y)) / (lineChartPoint.position.x-previousLineChartPoint.position.x); + + BOOL deltaFromNextSlope = ((currentSlope >= (nextSlope + kJBLineChartLinesViewSmoothThresholdSlope)) || (currentSlope <= (nextSlope - kJBLineChartLinesViewSmoothThresholdSlope))); + BOOL deltaFromPreviousSlope = ((currentSlope <= (previousSlope + kJBLineChartLinesViewSmoothThresholdSlope)) || (currentSlope >= (previousSlope - kJBLineChartLinesViewSmoothThresholdSlope))); + BOOL deltaFromPreviousY = (lineChartPoint.position.y >= previousLineChartPoint.position.y + kJBLineChartLinesViewSmoothThresholdVertical) || (lineChartPoint.position.y <= previousLineChartPoint.position.y - kJBLineChartLinesViewSmoothThresholdVertical); + + if ((index < lineData.count ? smoothLine : smoothBottomLine) && deltaFromNextSlope && deltaFromPreviousSlope && deltaFromPreviousY) + { + CGFloat deltaX = lineChartPoint.position.x - previousLineChartPoint.position.x; + CGFloat controlPointX = previousLineChartPoint.position.x + (deltaX / 2); + + CGPoint controlPoint1 = CGPointMake(controlPointX, previousLineChartPoint.position.y); + CGPoint controlPoint2 = CGPointMake(controlPointX, lineChartPoint.position.y); + + [fillingPath addCurveToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y))) controlPoint1:controlPoint1 controlPoint2:controlPoint2]; + } + else + { + [fillingPath addLineToPoint:CGPointMake(lineChartPoint.position.x, fmin(self.bounds.size.height - padding, fmax(padding, lineChartPoint.position.y)))]; + } + + previousSlope = currentSlope; + } + previousLineChartPoint = lineChartPoint; + index++; + } + + [fillingPath closePath]; + + fillingBottomLineIndex = lineIndex; + } - JBLineLayer *shapeLayer = [self lineLayerForLineIndex:lineIndex]; - if (shapeLayer == nil) + JBLineLayer *lineLayer = [self lineLayerForLineIndex:lineIndex]; + if (lineLayer == nil) { - shapeLayer = [JBLineLayer layer]; + lineLayer = [JBLineLayer layer]; } + JBAreaLayer *areaLayer = [self areaLayerForLineIndex:lineIndex]; + if (areaLayer == nil) + { + areaLayer = [JBAreaLayer layer]; + } + - shapeLayer.tag = lineIndex; + lineLayer.tag = lineIndex; + areaLayer.tag = lineIndex; NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:lineStyleForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (JBLineChartViewLineStyle)lineChartLineView:(JBLineChartLinesView *)lineChartLinesView lineStyleForLineAtLineIndex:(NSUInteger)lineIndex"); - shapeLayer.lineStyle = [self.delegate lineChartLinesView:self lineStyleForLineAtLineIndex:lineIndex]; + lineLayer.lineStyle = [self.delegate lineChartLinesView:self lineStyleForLineAtLineIndex:lineIndex]; NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:colorForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView colorForLineAtLineIndex:(NSUInteger)lineIndex"); - shapeLayer.strokeColor = [self.delegate lineChartLinesView:self colorForLineAtLineIndex:lineIndex].CGColor; - + UIColor *color = [self.delegate lineChartLinesView:self colorForLineAtLineIndex:lineIndex]; + lineLayer.strokeColor = color.CGColor; + areaLayer.fillColor = [color colorWithAlphaComponent:CGColorGetAlpha(color.CGColor)/2.0].CGColor; + if (smoothLine == YES) { - shapeLayer.lineCap = kCALineCapRound; - shapeLayer.lineJoin = kCALineJoinRound; + lineLayer.lineCap = kCALineCapRound; + lineLayer.lineJoin = kCALineJoinRound; + areaLayer.lineCap = kCALineCapRound; + areaLayer.lineJoin = kCALineJoinRound; } else { - shapeLayer.lineCap = kCALineCapButt; - shapeLayer.lineJoin = kCALineJoinMiter; + lineLayer.lineCap = kCALineCapButt; + lineLayer.lineJoin = kCALineJoinMiter; + areaLayer.lineCap = kCALineCapButt; + areaLayer.lineJoin = kCALineJoinMiter; } NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:widthForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (CGFloat)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView widthForLineAtLineIndex:(NSUInteger)lineIndex"); - shapeLayer.lineWidth = [self.delegate lineChartLinesView:self widthForLineAtLineIndex:lineIndex]; - shapeLayer.path = path.CGPath; - shapeLayer.frame = self.bounds; - [self.layer addSublayer:shapeLayer]; + lineLayer.lineWidth = [self.delegate lineChartLinesView:self widthForLineAtLineIndex:lineIndex]; + areaLayer.lineWidth = [self.delegate lineChartLinesView:self widthForLineAtLineIndex:lineIndex]; + lineLayer.path = path.CGPath; + areaLayer.path = fillingPath.CGPath; + lineLayer.frame = self.bounds; + areaLayer.frame = self.bounds; + [self.layer addSublayer:lineLayer]; + [self.layer insertSublayer:areaLayer atIndex:0]; lineIndex++; } @@ -1156,7 +1314,7 @@ - (void)setSelectedLineIndex:(NSInteger)selectedLineIndex animated:(BOOL)animate dispatch_block_t adjustLines = ^{ for (CALayer *layer in [self.layer sublayers]) { - if ([layer isKindOfClass:[JBLineLayer class]]) + if ([layer isMemberOfClass:[JBLineLayer class]]) { if (((JBLineLayer *)layer).tag == _selectedLineIndex) { @@ -1171,6 +1329,23 @@ - (void)setSelectedLineIndex:(NSInteger)selectedLineIndex animated:(BOOL)animate ((JBLineLayer *)layer).opacity = (_selectedLineIndex == kJBLineChartLinesViewUnselectedLineIndex) ? 1.0f : kJBLineChartLinesViewDefaultDimmedOpacity; } } + else if ([layer isMemberOfClass:[JBAreaLayer class]]) + { + if (((JBAreaLayer *)layer).tag == _selectedLineIndex) + { + NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:selectedColorForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectedColorForLineAtLineIndex:(NSUInteger)lineIndex"); + UIColor *lineColor = [self.delegate lineChartLinesView:self selectedColorForLineAtLineIndex:((JBAreaLayer *)layer).tag]; + ((JBAreaLayer *)layer).fillColor = [lineColor colorWithAlphaComponent:CGColorGetAlpha(lineColor.CGColor)/2.0].CGColor; + ((JBAreaLayer *)layer).opacity = 1.0f; + } + else + { + NSAssert([self.delegate respondsToSelector:@selector(lineChartLinesView:selectedColorForLineAtLineIndex:)], @"JBLineChartLinesView // delegate must implement - (UIColor *)lineChartLinesView:(JBLineChartLinesView *)lineChartLinesView selectedColorForLineAtLineIndex:(NSUInteger)lineIndex"); + UIColor *lineColor = [self.delegate lineChartLinesView:self colorForLineAtLineIndex:((JBAreaLayer *)layer).tag]; + ((JBAreaLayer *)layer).fillColor = [lineColor colorWithAlphaComponent:CGColorGetAlpha(lineColor.CGColor)/2.0].CGColor; + ((JBAreaLayer *)layer).opacity = (_selectedLineIndex == kJBLineChartLinesViewUnselectedLineIndex) ? 1.0f : kJBLineChartLinesViewDefaultDimmedOpacity; + } + } } }; @@ -1218,6 +1393,21 @@ - (JBLineLayer *)lineLayerForLineIndex:(NSUInteger)lineIndex return nil; } +- (JBAreaLayer *)areaLayerForLineIndex:(NSUInteger)areaIndex +{ + for (CALayer *layer in [self.layer sublayers]) + { + if ([layer isKindOfClass:[JBAreaLayer class]]) + { + if (((JBAreaLayer *)layer).tag == areaIndex) + { + return (JBAreaLayer *)layer; + } + } + } + return nil; +} + @end @implementation JBLineChartDotsView diff --git a/JBChartViewDemo/JBChartViewDemo/Cells/JBChartTableCell.h b/JBChartViewDemo/JBChartViewDemo/Cells/JBChartTableCell.h index 788ceb67e..e2cae790c 100644 --- a/JBChartViewDemo/JBChartViewDemo/Cells/JBChartTableCell.h +++ b/JBChartViewDemo/JBChartViewDemo/Cells/JBChartTableCell.h @@ -10,6 +10,7 @@ typedef NS_ENUM(NSInteger, JBChartTableCellType){ JBChartTableCellTypeLineChart, + JBChartTableCellTypeAreaChart, JBChartTableCellTypeBarChart }; diff --git a/JBChartViewDemo/JBChartViewDemo/Constants/JBStringConstants.h b/JBChartViewDemo/JBChartViewDemo/Constants/JBStringConstants.h index 4cd6a1314..62acff4a5 100644 --- a/JBChartViewDemo/JBChartViewDemo/Constants/JBStringConstants.h +++ b/JBChartViewDemo/JBChartViewDemo/Constants/JBStringConstants.h @@ -26,4 +26,4 @@ #define kJBStringLabelAverageDailyRainfall localize(@"label.average.daily.rainfall", @"Average Daily Rainfall") #define kJBStringLabelMm localize(@"label.mm", @"mm") #define kJBStringLabelMetropolitanAverage localize(@"label.metropolitan.average", @"Metropolitan Average") -#define kJBStringLabelNationalAverage localize(@"label.national.average", @"National Average") +#define kJBStringLabelNationalAverage localize(@"label.national.average", @"National Average") \ No newline at end of file diff --git a/JBChartViewDemo/JBChartViewDemo/Controllers/JBChartListViewController.m b/JBChartViewDemo/JBChartViewDemo/Controllers/JBChartListViewController.m index bb75d64c2..f66a11000 100644 --- a/JBChartViewDemo/JBChartViewDemo/Controllers/JBChartListViewController.m +++ b/JBChartViewDemo/JBChartViewDemo/Controllers/JBChartListViewController.m @@ -50,7 +50,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - JBChartTableCell *cell = [tableView dequeueReusableCellWithIdentifier:kJBChartListViewControllerCellIdentifier forIndexPath:indexPath]; + JBChartTableCell *cell = [tableView dequeueReusableCellWithIdentifier:kJBChartListViewControllerCellIdentifier forIndexPath:indexPath]; cell.textLabel.text = indexPath.row == JBChartListViewControllerRowLineChart ? kJBStringLabelAverageDailyRainfall : kJBStringLabelAverageMonthlyTemperature; cell.detailTextLabel.text = indexPath.row == JBChartListViewControllerRowLineChart ? kJBStringLabelSanFrancisco2013 : kJBStringLabelWorldwide2012; cell.type = indexPath.row == JBChartListViewControllerRowLineChart ? JBChartTableCellTypeLineChart : JBChartTableCellTypeBarChart; @@ -67,7 +67,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; - + if (indexPath.row == JBChartListViewControllerRowLineChart) { JBLineChartViewController *lineChartController = [[JBLineChartViewController alloc] init]; diff --git a/JBChartViewDemo/JBChartViewDemo/Controllers/JBLineChartViewController.m b/JBChartViewDemo/JBChartViewDemo/Controllers/JBLineChartViewController.m index f42fb4ec9..9a60e7c36 100644 --- a/JBChartViewDemo/JBChartViewDemo/Controllers/JBLineChartViewController.m +++ b/JBChartViewDemo/JBChartViewDemo/Controllers/JBLineChartViewController.m @@ -161,7 +161,7 @@ - (void)loadView [self.informationView setTextShadowColor:nil]; [self.informationView setSeparatorColor:kJBColorLineChartHeaderSeparatorColor]; [self.view addSubview:self.informationView]; - + [self.lineChartView reloadData]; } @@ -256,6 +256,12 @@ - (BOOL)lineChartView:(JBLineChartView *)lineChartView smoothLineAtLineIndex:(NS return lineIndex == JBLineChartViewLineStyleSolid; } +-(BOOL)lineChartView:(JBLineChartView *)lineChartView fillsAreaUnderLineWithIndex:(NSUInteger)lineIndex +{ + return lineIndex == JBLineChartLineSolid; +} + + #pragma mark - Buttons - (void)chartToggleButtonPressed:(id)sender