Peter Easdown

1. PNBar now allows you to specify a color for the label.

2. You can specify the border color for a PNBarChart
3. Fixed some problems in PNBarChart whereby the top and bottom margins were not being respected.
4. PNLineChart now has the same margin properties as PNBarChart so that you can overlay them and have the bars and the points in the LineChart line-up nicely.
5. You can now specify for a PNLineChart that points display their value using a font, format and color, just above the point itself.
6. A PNLineChartDataItem can now have two values, a raw value for displaying via the formatter, and the graded value which is used to determine the position of the data point.  The former is new.  This allows you to have multiple line charts that have different min-max values and yet overlay them.  The new value can then be used to display a value meaningful to the user whilst the old value is used to render the chart point.
... ... @@ -26,6 +26,9 @@
@property (nonatomic) CAShapeLayer *gradeLayer;
@property (nonatomic) CATextLayer* textLayer;
/** Text color for all bars in the chart. */
@property (nonatomic) UIColor * labelTextColor;
@property (nonatomic, assign) BOOL isNegative; //!< 是否是负数
@property (nonatomic, assign) BOOL isShowNumber; //!< 是否显示numbers
@end
... ...
... ... @@ -181,7 +181,7 @@
_textLayer = [[CATextLayer alloc]init];
[_textLayer setString:@"0"];
[_textLayer setAlignmentMode:kCAAlignmentCenter];
[_textLayer setForegroundColor:[[UIColor colorWithRed:178/255.0 green:178/255. blue:178/255.0 alpha:1.0] CGColor]];
[_textLayer setForegroundColor:[_labelTextColor CGColor]];
_textLayer.hidden = YES;
}
... ... @@ -189,6 +189,11 @@
return _textLayer;
}
- (void) setLabelTextColor:(UIColor *)labelTextColor {
_labelTextColor = labelTextColor;
[_textLayer setForegroundColor:[_labelTextColor CGColor]];
}
-(void)setGradeFrame:(CGFloat)grade startPosY:(CGFloat)startPosY
{
CGFloat textheigt = self.bounds.size.height*self.grade;
... ...
... ... @@ -63,6 +63,8 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue);
/** Controls whether the chart border line should be displayed. */
@property (nonatomic) BOOL showChartBorder;
@property (nonatomic) UIColor *chartBorderColor;
/** Controls whether the chart Horizontal separator should be displayed. */
@property (nonatomic, assign) BOOL showLevelLine;
... ...
... ... @@ -62,6 +62,7 @@
_chartMarginBottom = 25.0;
_barRadius = 2.0;
_showChartBorder = NO;
_chartBorderColor = PNLightGrey;
_showLevelLine = NO;
_yChartLabelWidth = 18;
_rotateForXAxisText = false;
... ... @@ -234,7 +235,7 @@
}
bar = [[PNBar alloc] initWithFrame:CGRectMake(barXPosition, //Bar X position
self.frame.size.height - chartCavanHeight - kXLabelHeight - _chartMarginTop , //Bar Y position
self.frame.size.height - chartCavanHeight - kXLabelHeight - _chartMarginBottom + _chartMarginTop , //Bar Y position
barWidth, // Bar witdh
self.showLevelLine ? chartCavanHeight/2.0:chartCavanHeight)]; //Bar height
... ... @@ -249,6 +250,10 @@
}else{
bar.barColor = [self barColorAtIndex:index];
}
if (self.labelTextColor) {
bar.labelTextColor = self.labelTextColor;
}
// Add gradient
if (self.isGradientShow) {
... ... @@ -309,13 +314,13 @@
UIBezierPath *progressline = [UIBezierPath bezierPath];
[progressline moveToPoint:CGPointMake(_chartMarginLeft, self.frame.size.height - kXLabelHeight - _chartMarginTop)];
[progressline addLineToPoint:CGPointMake(self.frame.size.width - _chartMarginRight, self.frame.size.height - kXLabelHeight - _chartMarginTop)];
[progressline moveToPoint:CGPointMake(_chartMarginLeft, self.frame.size.height - kXLabelHeight - _chartMarginBottom + _chartMarginTop)];
[progressline addLineToPoint:CGPointMake(self.frame.size.width - _chartMarginRight, self.frame.size.height - kXLabelHeight - _chartMarginBottom + _chartMarginTop)];
[progressline setLineWidth:1.0];
[progressline setLineCapStyle:kCGLineCapSquare];
_chartBottomLine.path = progressline.CGPath;
_chartBottomLine.strokeColor = PNLightGrey.CGColor;
_chartBottomLine.strokeColor = [_chartBorderColor CGColor];;
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration = 0.5;
... ... @@ -344,7 +349,7 @@
[progressLeftline setLineWidth:1.0];
[progressLeftline setLineCapStyle:kCGLineCapSquare];
_chartLeftLine.path = progressLeftline.CGPath;
_chartLeftLine.strokeColor = PNLightGrey.CGColor;
_chartLeftLine.strokeColor = [_chartBorderColor CGColor];
CABasicAnimation *pathLeftAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathLeftAnimation.duration = 0.5;
... ...
... ... @@ -45,11 +45,14 @@
@property (nonatomic) UIColor *yLabelColor;
@property (nonatomic) CGFloat chartCavanHeight;
@property (nonatomic) CGFloat chartCavanWidth;
@property (nonatomic) CGFloat chartMargin;
@property (nonatomic) BOOL showLabel;
@property (nonatomic) BOOL showGenYLabels;
@property (nonatomic) BOOL thousandsSeparator;
@property (nonatomic) CGFloat chartMarginLeft;
@property (nonatomic) CGFloat chartMarginRight;
@property (nonatomic) CGFloat chartMarginTop;
@property (nonatomic) CGFloat chartMarginBottom;
/**
* Controls whether to show the coordinate axis. Default is NO.
... ...
This diff is collapsed. Click to expand it.
... ... @@ -25,6 +25,11 @@ typedef PNLineChartDataItem *(^LCLineChartDataGetter)(NSUInteger item);
@property (copy) LCLineChartDataGetter getData;
@property (strong, nonatomic) NSString *dataTitle;
@property (nonatomic) BOOL showPointLabel;
@property (nonatomic) UIColor *pointLabelColor;
@property (nonatomic) UIFont *pointLabelFont;
@property (nonatomic) NSString *pointLabelFormat;
@property (nonatomic, assign) PNLineChartPointStyle inflexionPointStyle;
/**
... ...
... ... @@ -23,6 +23,9 @@
_inflexionPointWidth = 6.f;
_lineWidth = 2.f;
_alpha = 1.f;
_showPointLabel = NO;
_pointLabelColor = [UIColor blackColor];
_pointLabelFormat = @"%1.f";
}
@end
... ...
... ... @@ -9,7 +9,9 @@
@interface PNLineChartDataItem : NSObject
+ (PNLineChartDataItem *)dataItemWithY:(CGFloat)y;
+ (PNLineChartDataItem *)dataItemWithY:(CGFloat)y andRawY:(CGFloat)rawY;
@property (readonly) CGFloat y; // should be within the y range
@property (readonly) CGFloat rawY; // this is the raw value, used for point label.
@end
... ...
... ... @@ -7,9 +7,10 @@
@interface PNLineChartDataItem ()
- (id)initWithY:(CGFloat)y;
- (id)initWithY:(CGFloat)y andRawY:(CGFloat)rawY;
@property (readwrite) CGFloat y; // should be within the y range
@property (readwrite) CGFloat y; // should be within the y range
@property (readwrite) CGFloat rawY; // this is the raw value, used for point label.
@end
... ... @@ -17,13 +18,18 @@
+ (PNLineChartDataItem *)dataItemWithY:(CGFloat)y
{
return [[PNLineChartDataItem alloc] initWithY:y];
return [[PNLineChartDataItem alloc] initWithY:y andRawY:y];
}
- (id)initWithY:(CGFloat)y
+ (PNLineChartDataItem *)dataItemWithY:(CGFloat)y andRawY:(CGFloat)rawY {
return [[PNLineChartDataItem alloc] initWithY:y andRawY:rawY];
}
- (id)initWithY:(CGFloat)y andRawY:(CGFloat)rawY
{
if ((self = [super init])) {
self.y = y;
self.rawY = rawY;
}
return self;
... ...