kevinzhow

Merge branch 'master' of github.com:kevinzhow/PNChart

... ... @@ -17,6 +17,7 @@ DerivedData
.idea/
*.hmap
*.xccheckout
Build/
#CocoaPods
Pods
... ...
... ... @@ -16,7 +16,6 @@
self = [super initWithFrame:frame];
if (self) {
// Initialization code
_chartLine = [CAShapeLayer layer];
_chartLine.lineCap = kCALineCapButt;
_chartLine.fillColor = [[UIColor whiteColor] CGColor];
... ... @@ -64,20 +63,19 @@
[_chartLine addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
_chartLine.strokeEnd = 1.0;
// Check if user wants to add a gradient from the start color to the bar color
if (_barColorGradientStart) {
// Add gradient
CAShapeLayer *gradientMask = [CAShapeLayer layer];
gradientMask.fillColor = [[UIColor clearColor] CGColor];
gradientMask.strokeColor = [[UIColor blackColor] CGColor];
//gradientMask.lineWidth = 4;
gradientMask.lineWidth = self.frame.size.width;
gradientMask.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
gradientMask.path = progressline.CGPath;
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.startPoint = CGPointMake(0.5,1.0);
gradientLayer.endPoint = CGPointMake(0.5,0.0);
... ... @@ -88,11 +86,11 @@
(id)endColor.CGColor
];
gradientLayer.colors = colors;
[gradientLayer setMask:gradientMask];
[_chartLine addSublayer:gradientLayer];
gradientMask.strokeEnd = 1.0;
[gradientMask addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
}
... ... @@ -114,16 +112,15 @@
[sublayer removeFromSuperlayer];
}
_barColorGradientStart = barColorGradientStart;
[self setGrade:_grade];
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
//Draw BG
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, self.backgroundColor.CGColor);
... ...
... ... @@ -15,14 +15,13 @@
#define yLabelHeight 11
#define xLabelHeight 20
typedef NSString *(^PNyLabelFromatter)(CGFloat yLabelValue);
typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue);
@interface PNBarChart : UIView
/**
* This method will call and stroke the line in animation
* Draws the chart in an animated fashion.
*/
- (void)strokeChart;
@property (nonatomic) NSArray *xLabels;
... ... @@ -37,98 +36,58 @@ typedef NSString *(^PNyLabelFromatter)(CGFloat yLabelValue);
@property (nonatomic) NSArray *strokeColors;
/*
chartMargin changes chart margin
*/
/** Changes chart margin. */
@property (nonatomic) CGFloat yChartLabelWidth;
/*
yLabelFormatter will format the ylabel text
*/
@property (copy) PNyLabelFromatter yLabelFormatter;
/** Formats the ylabel text. */
@property (copy) PNYLabelFormatter yLabelFormatter;
/*
chartMargin changes chart margin
*/
@property (nonatomic) CGFloat chartMargin;
/*
showLabelDefines if the Labels should be deplay
*/
/** Controls whether labels should be displayed. */
@property (nonatomic) BOOL showLabel;
/*
showChartBorder if the chart border Line should be deplay
*/
/** Controls whether the chart border line should be displayed. */
@property (nonatomic) BOOL showChartBorder;
/*
chartBottomLine the Line at the chart bottom
*/
/** Chart bottom border, co-linear with the x-axis. */
@property (nonatomic) CAShapeLayer * chartBottomLine;
/*
chartLeftLine the Line at the chart left
*/
/** Chart left border, co-linear with the y-axis. */
@property (nonatomic) CAShapeLayer * chartLeftLine;
/*
barRadius changes the bar corner radius
*/
/** Corner radius for all bars in the chart. */
@property (nonatomic) CGFloat barRadius;
/*
barWidth changes the width of the bar
*/
/** Width of all bars in the chart. */
@property (nonatomic) CGFloat barWidth;
/*
labelMarginTop changes the width of the bar
*/
@property (nonatomic) CGFloat labelMarginTop;
/*
barBackgroundColor changes the bar background color
*/
/** Background color of all bars in the chart. */
@property (nonatomic) UIColor * barBackgroundColor;
/*
labelTextColor changes the bar label text color
*/
/** Text color for all bars in the chart. */
@property (nonatomic) UIColor * labelTextColor;
/*
labelFont changes the bar label font
*/
/** Font for all bars in the chart. */
@property (nonatomic) UIFont * labelFont;
/*
xLabelSkip define the label skip number
*/
/** How many labels on the x-axis to skip in between displaying labels. */
@property (nonatomic) NSInteger xLabelSkip;
/*
yLabelSum define the label sum number
*/
/** How many labels on the y-axis to skip in between displaying labels. */
@property (nonatomic) NSInteger yLabelSum;
/*
yMaxValue define the max value of the chart
*/
/** The maximum for the range of values to display on the y-axis. */
@property (nonatomic) CGFloat yMaxValue;
/*
yMinValue define the min value of the chart
*/
/** The minimum for the range of values to display on the y-axis. */
@property (nonatomic) CGFloat yMinValue;
/*
switch to indicate that the bar should be filled as a gradient
*/
/** Controls whether each bar should have a gradient fill. */
@property (nonatomic) UIColor *barColorGradientStart;
@property (nonatomic, retain) id<PNChartDelegate> delegate;
@end
... ...
... ... @@ -26,7 +26,6 @@
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.backgroundColor = [UIColor whiteColor];
self.clipsToBounds = YES;
_showLabel = YES;
... ... @@ -51,13 +50,13 @@
- (void)setYValues:(NSArray *)yValues
{
_yValues = yValues;
if (_yMaxValue) {
_yValueMax = _yMaxValue;
}else{
} else {
[self getYValueMax:yValues];
}
_xLabelWidth = (self.frame.size.width - _chartMargin * 2) / [_yValues count];
}
... ... @@ -65,21 +64,14 @@
- (void)getYValueMax:(NSArray *)yLabels
{
int max = [[yLabels valueForKeyPath:@"@max.intValue"] intValue];
_yValueMax = (int)max;
if (_yValueMax == 0) {
_yValueMax = _yMinValue;
}
}
- (void)setYLabels:(NSArray *)yLabels
{
}
- (void)setXLabels:(NSArray *)xLabels
{
_xLabels = xLabels;
... ... @@ -105,7 +97,7 @@
int labelAddCount = 0;
for (int index = 0; index < _xLabels.count; index++) {
labelAddCount += 1;
if (labelAddCount == _xLabelSkip) {
NSString *labelText = [_xLabels[index] description];
PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectZero];
... ... @@ -115,24 +107,24 @@
label.text = labelText;
[label sizeToFit];
CGFloat labelXPosition = (index * _xLabelWidth + _chartMargin + _xLabelWidth /2.0 );
label.center = CGPointMake(labelXPosition,
self.frame.size.height - xLabelHeight - _chartMargin + label.frame.size.height /2.0 + _labelMarginTop);
labelAddCount = 0;
[_labels addObject:label];
[self addSubview:label];
}
}
//Add y labels
float yLabelSectionHeight = (self.frame.size.height - _chartMargin * 2 - xLabelHeight) / _yLabelSum;
for (int index = 0; index < _yLabelSum; index++) {
NSString *labelText = _yLabelFormatter((float)_yValueMax * ( (_yLabelSum - index) / (float)_yLabelSum ));
PNChartLabel * label = [[PNChartLabel alloc] initWithFrame:CGRectMake(0,
yLabelSectionHeight * index + _chartMargin - yLabelHeight/2.0,
_yChartLabelWidth,
... ... @@ -147,11 +139,11 @@
}
}
[self viewCleanupForCollection:_bars];
//Add bars
CGFloat chartCavanHeight = self.frame.size.height - _chartMargin * 2 - xLabelHeight;
NSInteger index = 0;
... ... @@ -160,15 +152,15 @@
float value = [valueString floatValue];
float grade = (float)value / (float)_yValueMax;
if (isnan(grade)) {
grade = 0;
}
PNBar *bar;
CGFloat barWidth;
CGFloat barXPosition;
if (_barWidth) {
barWidth = _barWidth;
barXPosition = index * _xLabelWidth + _chartMargin + _xLabelWidth /2.0 - _barWidth /2.0;
... ... @@ -176,112 +168,112 @@
barXPosition = index * _xLabelWidth + _chartMargin + _xLabelWidth * 0.25;
if (_showLabel) {
barWidth = _xLabelWidth * 0.5;
}
else {
barWidth = _xLabelWidth * 0.6;
}
}
bar = [[PNBar alloc] initWithFrame:CGRectMake(barXPosition, //Bar X position
self.frame.size.height - chartCavanHeight - xLabelHeight - _chartMargin, //Bar Y position
barWidth, // Bar witdh
chartCavanHeight)]; //Bar height
//Change Bar Radius
bar.barRadius = _barRadius;
//Change Bar Background color
bar.backgroundColor = _barBackgroundColor;
//Bar StrokColor First
if (self.strokeColor) {
bar.barColor = self.strokeColor;
}else{
bar.barColor = [self barColorAtIndex:index];
}
//Height Of Bar
bar.grade = grade;
// Add gradient
bar.barColorGradientStart = _barColorGradientStart;
//For Click Index
bar.tag = index;
[_bars addObject:bar];
[self addSubview:bar];
index += 1;
}
//Add chart border lines
if (_showChartBorder) {
_chartBottomLine = [CAShapeLayer layer];
_chartBottomLine.lineCap = kCALineCapButt;
_chartBottomLine.fillColor = [[UIColor whiteColor] CGColor];
_chartBottomLine.lineWidth = 1.0;
_chartBottomLine.strokeEnd = 0.0;
UIBezierPath *progressline = [UIBezierPath bezierPath];
[progressline moveToPoint:CGPointMake(_chartMargin, self.frame.size.height - xLabelHeight - _chartMargin)];
[progressline addLineToPoint:CGPointMake(self.frame.size.width - _chartMargin, self.frame.size.height - xLabelHeight - _chartMargin)];
[progressline setLineWidth:1.0];
[progressline setLineCapStyle:kCGLineCapSquare];
_chartBottomLine.path = progressline.CGPath;
_chartBottomLine.strokeColor = PNLightGrey.CGColor;
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration = 0.5;
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pathAnimation.fromValue = @0.0f;
pathAnimation.toValue = @1.0f;
[_chartBottomLine addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
_chartBottomLine.strokeEnd = 1.0;
[self.layer addSublayer:_chartBottomLine];
//Add left Chart Line
_chartLeftLine = [CAShapeLayer layer];
_chartLeftLine.lineCap = kCALineCapButt;
_chartLeftLine.fillColor = [[UIColor whiteColor] CGColor];
_chartLeftLine.lineWidth = 1.0;
_chartLeftLine.strokeEnd = 0.0;
UIBezierPath *progressLeftline = [UIBezierPath bezierPath];
[progressLeftline moveToPoint:CGPointMake(_chartMargin, self.frame.size.height - xLabelHeight - _chartMargin)];
[progressLeftline addLineToPoint:CGPointMake(_chartMargin, _chartMargin)];
[progressLeftline setLineWidth:1.0];
[progressLeftline setLineCapStyle:kCGLineCapSquare];
_chartLeftLine.path = progressLeftline.CGPath;
_chartLeftLine.strokeColor = PNLightGrey.CGColor;
CABasicAnimation *pathLeftAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathLeftAnimation.duration = 0.5;
pathLeftAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pathLeftAnimation.fromValue = @0.0f;
pathLeftAnimation.toValue = @1.0f;
[_chartLeftLine addAnimation:pathLeftAnimation forKey:@"strokeEndAnimation"];
_chartLeftLine.strokeEnd = 1.0;
[self.layer addSublayer:_chartLeftLine];
}
}
... ... @@ -324,9 +316,9 @@
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
UIView *subview = [self hitTest:touchPoint withEvent:nil];
if ([subview isKindOfClass:[PNBar class]] && [self.delegate respondsToSelector:@selector(userClickedOnBarCharIndex:)]) {
[self.delegate userClickedOnBarCharIndex:subview.tag];
if ([subview isKindOfClass:[PNBar class]] && [self.delegate respondsToSelector:@selector(userClickedOnBarAtIndex:)]) {
[self.delegate userClickedOnBarAtIndex:subview.tag];
}
}
... ...
... ... @@ -11,21 +11,20 @@
@protocol PNChartDelegate <NSObject>
/**
* When user click on the chart line
*
* Callback method that gets invoked when the user taps on the chart line.
*/
- (void)userClickedOnLinePoint:(CGPoint)point lineIndex:(NSInteger)lineIndex;
/**
* When user click on the chart line key point
*
* Callback method that gets invoked when the user taps on a chart line key point.
*/
- (void)userClickedOnLineKeyPoint:(CGPoint)point lineIndex:(NSInteger)lineIndex andPointIndex:(NSInteger)pointIndex;
- (void)userClickedOnLineKeyPoint:(CGPoint)point
lineIndex:(NSInteger)lineIndex
pointIndex:(NSInteger)pointIndex;
/**
* When user click on a chart bar
*
* Callback method that gets invoked when the user taps on a chart bar.
*/
- (void)userClickedOnBarCharIndex:(NSInteger)barIndex;
- (void)userClickedOnBarAtIndex:(NSInteger)barIndex;
@end
\ No newline at end of file
... ...
... ... @@ -7,7 +7,6 @@
//
#import "PNChartLabel.h"
#import "PNColor.h"
@implementation PNChartLabel
... ... @@ -16,8 +15,6 @@
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.font = [UIFont boldSystemFontOfSize:11.0f];
self.backgroundColor = [UIColor clearColor];
self.textAlignment = NSTextAlignmentCenter;
... ...
... ... @@ -22,7 +22,11 @@ typedef NS_ENUM (NSUInteger, PNChartFormatType) {
- (void)strokeChart;
- (void)growChartByAmount:(NSNumber *)growAmount;
- (id)initWithFrame:(CGRect)frame andTotal:(NSNumber *)total andCurrent:(NSNumber *)current andClockwise:(BOOL)clockwise andShadow:(BOOL)hasBackgroundShadow;
- (id)initWithFrame:(CGRect)frame
total:(NSNumber *)total
current:(NSNumber *)current
clockwise:(BOOL)clockwise
shadow:(BOOL)hasBackgroundShadow;
@property (strong, nonatomic) UICountingLabel *countingLabel;
@property (nonatomic) UIColor *strokeColor;
... ... @@ -34,6 +38,6 @@ typedef NS_ENUM (NSUInteger, PNChartFormatType) {
@property (nonatomic) PNChartFormatType chartType;
@property (nonatomic) CAShapeLayer *circle;
@property (nonatomic) CAShapeLayer *circleBG;
@property (nonatomic) CAShapeLayer *circleBackground;
@end
... ...
... ... @@ -14,7 +14,11 @@
@implementation PNCircleChart
- (id)initWithFrame:(CGRect)frame andTotal:(NSNumber *)total andCurrent:(NSNumber *)current andClockwise:(BOOL)clockwise andShadow:(BOOL)hasBackgroundShadow
- (id)initWithFrame:(CGRect)frame
total:(NSNumber *)total
current:(NSNumber *)current
clockwise:(BOOL)clockwise
shadow:(BOOL)hasBackgroundShadow
{
self = [super initWithFrame:frame];
... ... @@ -29,7 +33,11 @@
CGFloat endAngle = clockwise ? -90.01f : 270.01f;
_lineWidth = @8.0f;
UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.center.x, self.center.y) radius:self.frame.size.height * 0.5 startAngle:DEGREES_TO_RADIANS(startAngle) endAngle:DEGREES_TO_RADIANS(endAngle) clockwise:clockwise];
UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.center.x, self.center.y)
radius:self.frame.size.height * 0.5
startAngle:DEGREES_TO_RADIANS(startAngle)
endAngle:DEGREES_TO_RADIANS(endAngle)
clockwise:clockwise];
_circle = [CAShapeLayer layer];
_circle.path = circlePath.CGPath;
... ... @@ -38,17 +46,17 @@
_circle.lineWidth = [_lineWidth floatValue];
_circle.zPosition = 1;
_circleBG = [CAShapeLayer layer];
_circleBG.path = circlePath.CGPath;
_circleBG.lineCap = kCALineCapRound;
_circleBG.fillColor = [UIColor clearColor].CGColor;
_circleBG.lineWidth = [_lineWidth floatValue];
_circleBG.strokeColor = (hasBackgroundShadow ? PNLightYellow.CGColor : [UIColor clearColor].CGColor);
_circleBG.strokeEnd = 1.0;
_circleBG.zPosition = -1;
_circleBackground = [CAShapeLayer layer];
_circleBackground.path = circlePath.CGPath;
_circleBackground.lineCap = kCALineCapRound;
_circleBackground.fillColor = [UIColor clearColor].CGColor;
_circleBackground.lineWidth = [_lineWidth floatValue];
_circleBackground.strokeColor = (hasBackgroundShadow ? PNLightYellow.CGColor : [UIColor clearColor].CGColor);
_circleBackground.strokeEnd = 1.0;
_circleBackground.zPosition = -1;
[self.layer addSublayer:_circle];
[self.layer addSublayer:_circleBG];
[self.layer addSublayer:_circleBackground];
_countingLabel = [[UICountingLabel alloc] initWithFrame:CGRectMake(0, 0, 100.0, 50.0)];
[_countingLabel setTextAlignment:NSTextAlignmentCenter];
... ... @@ -67,19 +75,19 @@
- (void)strokeChart
{
// Add counting label
NSString *format;
switch (self.chartType) {
case PNChartFormatTypePercent:
format = @"%d%%";
break;
case PNChartFormatTypeDollar:
format = @"$%d";
break;
case PNChartFormatTypeNone:
default:
format = @"%d";
break;
case PNChartFormatTypePercent:
format = @"%d%%";
break;
case PNChartFormatTypeDollar:
format = @"$%d";
break;
case PNChartFormatTypeNone:
default:
format = @"%d";
break;
}
self.countingLabel.format = format;
[self addSubview:self.countingLabel];
... ... @@ -88,8 +96,8 @@
// Add circle params
_circle.lineWidth = [_lineWidth floatValue];
_circleBG.lineWidth = [_lineWidth floatValue];
_circleBG.strokeEnd = 1.0;
_circleBackground.lineWidth = [_lineWidth floatValue];
_circleBackground.strokeEnd = 1.0;
_circle.strokeColor = _strokeColor.CGColor;
// Add Animation
... ... @@ -102,11 +110,11 @@
_circle.strokeEnd = [_current floatValue] / [_total floatValue];
[_countingLabel countFrom:0 to:[_current floatValue] withDuration:1.0];
// Check if user wants to add a gradient from the start color to the bar color
if (_strokeColorGradientStart) {
// Add gradient
CAShapeLayer *gradientMask = [CAShapeLayer layer];
gradientMask.fillColor = [[UIColor clearColor] CGColor];
... ... @@ -116,7 +124,7 @@
CGRect gradientFrame = CGRectMake(0, 0, 2*self.bounds.size.width, 2*self.bounds.size.height);
gradientMask.frame = gradientFrame;
gradientMask.path = _circle.path;
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.startPoint = CGPointMake(0.5,1.0);
gradientLayer.endPoint = CGPointMake(0.5,0.0);
... ... @@ -127,16 +135,15 @@
(id)_strokeColorGradientStart.CGColor
];
gradientLayer.colors = colors;
[gradientLayer setMask:gradientMask];
[_circle addSublayer:gradientLayer];
gradientMask.strokeEnd = [_current floatValue] / [_total floatValue];
[gradientMask addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
}
}
... ... @@ -144,7 +151,7 @@
- (void)growChartByAmount:(NSNumber *)growAmount
{
NSNumber *updatedValue = [NSNumber numberWithFloat:[_current floatValue] + [growAmount floatValue]];
// Add animation
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration = self.duration;
... ... @@ -153,7 +160,7 @@
pathAnimation.toValue = @([updatedValue floatValue] / [_total floatValue]);
_circle.strokeEnd = [updatedValue floatValue] / [_total floatValue];
[_circle addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
[self.countingLabel countFrom:fmin([_current floatValue], [_total floatValue]) to:fmin([_current floatValue] + [growAmount floatValue], [_total floatValue]) withDuration:self.duration];
_current = updatedValue;
}
... ...
... ... @@ -21,7 +21,7 @@
#define PNButtonGrey [UIColor colorWithRed:141.0 / 255.0 green:141.0 / 255.0 blue:141.0 / 255.0 alpha:1.0f]
#define PNLightGreen [UIColor colorWithRed:77.0 / 255.0 green:216.0 / 255.0 blue:122.0 / 255.0 alpha:1.0f]
#define PNFreshGreen [UIColor colorWithRed:77.0 / 255.0 green:196.0 / 255.0 blue:122.0 / 255.0 alpha:1.0f]
#define PNDeepGreen [UIColor colorWithRed:77.0 / 255.0 green:176.0 / 255.0 blue:122.0 / 255.0 alpha:1.0f]
#define PNDeepGreen [UIColor colorWithRed:77.0 / 255.0 green:176.0 / 255.0 blue:122.0 / 255.0 alpha:1.0f]
#define PNRed [UIColor colorWithRed:245.0 / 255.0 green:94.0 / 255.0 blue:78.0 / 255.0 alpha:1.0f]
#define PNMauve [UIColor colorWithRed:88.0 / 255.0 green:75.0 / 255.0 blue:103.0 / 255.0 alpha:1.0f]
#define PNBrown [UIColor colorWithRed:119.0 / 255.0 green:107.0 / 255.0 blue:95.0 / 255.0 alpha:1.0f]
... ...
... ... @@ -16,12 +16,11 @@
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context,
[color CGColor]);
// [[UIColor colorWithRed:222./255 green:227./255 blue: 229./255 alpha:1] CGColor]) ;
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
... ...
... ... @@ -13,15 +13,13 @@
@interface PNLineChart : UIView
/**
* This method will call and troke the line in animation
* Draws the chart in an animated fashion.
*/
- (void)strokeChart;
@property (nonatomic, retain) id<PNChartDelegate> delegate;
@property (nonatomic) NSArray *xLabels;
@property (nonatomic) NSArray *yLabels;
/**
... ... @@ -30,35 +28,22 @@
@property (nonatomic) NSArray *chartData;
@property (nonatomic) NSMutableArray *pathPoints;
@property (nonatomic) CGFloat xLabelWidth;
@property (nonatomic) UIFont *xLabelFont;
@property (nonatomic) UIColor *xLabelColor;
@property (nonatomic) CGFloat yValueMax;
@property (nonatomic) CGFloat yValueMin;
@property (nonatomic) NSInteger yLabelNum;
@property (nonatomic) CGFloat yLabelHeight;
@property (nonatomic) UIFont *yLabelFont;
@property (nonatomic) UIColor *yLabelColor;
@property (nonatomic) CGFloat chartCavanHeight;
@property (nonatomic) CGFloat chartCavanWidth;
@property (nonatomic) CGFloat chartMargin;
@property (nonatomic) BOOL showLabel;
/**
* show CoordinateAxis ornot, Default is not
* Controls whether to show the coordinate axis. Default is NO.
*/
@property (nonatomic, getter = isShowCoordinateAxis) BOOL showCoordinateAxis;
@property (nonatomic) UIColor *axisColor;
... ... @@ -68,7 +53,7 @@
@property (nonatomic, strong) NSString *yUnit;
/**
* String formatter for float values in y labels. If not set, defaults to @"%1.f"
* String formatter for float values in y-axis labels. If not set, defaults to @"%1.f"
*/
@property (nonatomic, strong) NSString *yLabelFormat;
... ...
... ... @@ -12,9 +12,6 @@
#import "PNLineChartData.h"
#import "PNLineChartDataItem.h"
// ------------------------------------------------------------------------------------------------
// private interface declaration
// ------------------------------------------------------------------------------------------------
@interface PNLineChart ()
@property (nonatomic) NSMutableArray *chartLineArray; // Array[CAShapeLayer]
... ... @@ -27,9 +24,6 @@
@end
// ------------------------------------------------------------------------------------------------
// public interface implementation
// ------------------------------------------------------------------------------------------------
@implementation PNLineChart
#pragma mark initialization
... ... @@ -222,7 +216,7 @@
if (distance <= 10.0) {
[_delegate userClickedOnLineKeyPoint:touchPoint
lineIndex:p
andPointIndex:(distance == distanceToP2 ? i + 1 : i)];
pointIndex:(distance == distanceToP2 ? i + 1 : i)];
return;
}
... ... @@ -285,8 +279,8 @@
int x = 2 * _chartMargin + (i * offSetX);
int y = _chartCavanHeight - (innerGrade * _chartCavanHeight) + (_yLabelHeight / 2);
// cycle style point
if (chartData.inflexionPointStyle == PNLineChartPointStyleCycle) {
// Circular point
if (chartData.inflexionPointStyle == PNLineChartPointStyleCircle) {
CGRect circleRect = CGRectMake(x - inflexionWidth / 2, y - inflexionWidth / 2, inflexionWidth, inflexionWidth);
CGPoint circleCenter = CGPointMake(circleRect.origin.x + (circleRect.size.width / 2), circleRect.origin.y + (circleRect.size.height / 2));
... ... @@ -310,7 +304,7 @@
last_x = x;
last_y = y;
}
// Square style point
// Square point
else if (chartData.inflexionPointStyle == PNLineChartPointStyleSquare) {
CGRect squareRect = CGRectMake(x - inflexionWidth / 2, y - inflexionWidth / 2, inflexionWidth, inflexionWidth);
... ... @@ -337,15 +331,6 @@
last_x = x;
last_y = y;
}
// Triangle style point
else if (chartData.inflexionPointStyle == PNLineChartPointStyleTriangle) {
if ( i != 0 ) {
[progressline addLineToPoint:CGPointMake(x, y)];
}
[progressline moveToPoint:CGPointMake(x, y)];
} else {
if ( i != 0 ) {
... ... @@ -388,9 +373,6 @@
[pointLayer addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
}
[CATransaction setCompletionBlock:^{
// pointLayer.strokeEnd = 1.0f; // stroken point when animation end
}];
[CATransaction commit];
UIGraphicsEndImageContext();
... ... @@ -416,7 +398,6 @@
self.chartLineArray = [NSMutableArray arrayWithCapacity:data.count];
self.chartPointArray = [NSMutableArray arrayWithCapacity:data.count];
// set for point stoken
for (PNLineChartData *chartData in data) {
// create as many chart line layers as there are data-lines
CAShapeLayer *chartLine = [CAShapeLayer layer];
... ... @@ -474,7 +455,7 @@
{
if (self.isShowCoordinateAxis) {
CGFloat yAsixOffset = 10.f;
CGFloat yAxisOffset = 10.f;
CGContextRef ctx = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(ctx);
... ... @@ -485,15 +466,15 @@
CGFloat yAxisHeight = _chartMargin + _chartCavanHeight;
// draw coordinate axis
CGContextMoveToPoint(ctx, _chartMargin + yAsixOffset, 0);
CGContextAddLineToPoint(ctx, _chartMargin + yAsixOffset, yAxisHeight);
CGContextMoveToPoint(ctx, _chartMargin + yAxisOffset, 0);
CGContextAddLineToPoint(ctx, _chartMargin + yAxisOffset, yAxisHeight);
CGContextAddLineToPoint(ctx, xAxisWidth, yAxisHeight);
CGContextStrokePath(ctx);
// draw y axis arrow
CGContextMoveToPoint(ctx, _chartMargin + yAsixOffset - 3, 6);
CGContextAddLineToPoint(ctx, _chartMargin + yAsixOffset, 0);
CGContextAddLineToPoint(ctx, _chartMargin + yAsixOffset + 3, 6);
CGContextMoveToPoint(ctx, _chartMargin + yAxisOffset - 3, 6);
CGContextAddLineToPoint(ctx, _chartMargin + yAxisOffset, 0);
CGContextAddLineToPoint(ctx, _chartMargin + yAxisOffset + 3, 6);
CGContextStrokePath(ctx);
// draw x axis arrow
... ... @@ -516,7 +497,7 @@
// draw y axis separator
CGFloat yStepHeight = _chartCavanHeight / _yLabelNum;
for (NSUInteger i = 0; i < [self.xLabels count]; i++) {
point = CGPointMake(_chartMargin + yAsixOffset, (_chartCavanHeight - i * yStepHeight + _yLabelHeight / 2));
point = CGPointMake(_chartMargin + yAxisOffset, (_chartCavanHeight - i * yStepHeight + _yLabelHeight / 2));
CGContextMoveToPoint(ctx, point.x, point.y);
CGContextAddLineToPoint(ctx, point.x + 2, point.y);
CGContextStrokePath(ctx);
... ...
... ... @@ -5,15 +5,10 @@
#import <Foundation/Foundation.h>
/**
* not support PNLineChartPointStyleTriangle style recently
*/
typedef NS_ENUM(NSUInteger, PNLineChartPointStyle) {
PNLineChartPointStyleNone = 0,
PNLineChartPointStyleCycle,
PNLineChartPointStyleTriangle,
PNLineChartPointStyleSquare
PNLineChartPointStyleCircle = 1,
PNLineChartPointStyleSquare = 3
};
@class PNLineChartDataItem;
... ... @@ -29,9 +24,8 @@ typedef PNLineChartDataItem *(^LCLineChartDataGetter)(NSUInteger item);
@property (nonatomic, assign) PNLineChartPointStyle inflexionPointStyle;
/**
* if PNLineChartPointStyle is cycle, inflexionPointWidth equal cycle's diameter
* if PNLineChartPointStyle is square, that means the foundation is square with
* inflexionPointWidth long
* If PNLineChartPointStyle is circle, this returns the circle's diameter.
* If PNLineChartPointStyle is square, each point is a square with each side equal in length to this value.
*/
@property (nonatomic, assign) CGFloat inflexionPointWidth;
... ...
... ... @@ -11,7 +11,6 @@
{
self = [super init];
if (self) {
[self setDefaultValues];
}
... ...
... ... @@ -5,21 +5,14 @@
#import "PNLineChartDataItem.h"
//------------------------------------------------------------------------------------------------
// private interface declaration
//------------------------------------------------------------------------------------------------
@interface PNLineChartDataItem ()
- (id)initWithY:(CGFloat)y;
@property (readwrite) CGFloat y; // should be within the y range
@end
@end
//------------------------------------------------------------------------------------------------
// public interface implementation
//------------------------------------------------------------------------------------------------
@implementation PNLineChartDataItem
+ (PNLineChartDataItem *)dataItemWithY:(CGFloat)y
... ... @@ -27,7 +20,6 @@
return [[PNLineChartDataItem alloc] initWithY:y];
}
- (id)initWithY:(CGFloat)y
{
if ((self = [super init])) {
... ... @@ -37,5 +29,4 @@
return self;
}
@end
... ...
... ... @@ -15,11 +15,20 @@
@property (nonatomic, readonly) NSArray *items;
@property (nonatomic) UIFont *descriptionTextFont; //default is [UIFont fontWithName:@"Avenir-Medium" size:18.0];
@property (nonatomic) UIColor *descriptionTextColor; //default is [UIColor whiteColor]
@property (nonatomic) UIColor *descriptionTextShadowColor; //default is [[UIColor blackColor] colorWithAlphaComponent:0.4]
@property (nonatomic) CGSize descriptionTextShadowOffset; //default is CGSizeMake(0, 1)
@property (nonatomic) NSTimeInterval duration;//default is 1.0
/** Default is 18-point Avenir Medium. */
@property (nonatomic) UIFont *descriptionTextFont;
/** Default is white. */
@property (nonatomic) UIColor *descriptionTextColor;
/** Default is black, with an alpha of 0.4. */
@property (nonatomic) UIColor *descriptionTextShadowColor;
/** Default is CGSizeMake(0, 1). */
@property (nonatomic) CGSize descriptionTextShadowOffset;
/** Default is 1.0. */
@property (nonatomic) NSTimeInterval duration;
- (void)strokeChart;
... ...
... ... @@ -14,7 +14,7 @@
@property (nonatomic) CGFloat total;
@property (nonatomic) CGFloat currentTotal;
@property (nonatomic) CGFloat outterCircleRadius;
@property (nonatomic) CGFloat outerCircleRadius;
@property (nonatomic) CGFloat innerCircleRadius;
@property (nonatomic) UIView *contentView;
... ... @@ -43,7 +43,7 @@
self = [self initWithFrame:frame];
if(self){
_items = [NSArray arrayWithArray:items];
_outterCircleRadius = CGRectGetWidth(self.bounds)/2;
_outerCircleRadius = CGRectGetWidth(self.bounds)/2;
_innerCircleRadius = CGRectGetWidth(self.bounds)/6;
_descriptionTextColor = [UIColor whiteColor];
... ... @@ -91,8 +91,8 @@
CGFloat startPercnetage = currentValue/_total;
CGFloat endPercentage = (currentValue + currentItem.value)/_total;
CAShapeLayer *currentPieLayer = [self newCircleLayerWithRadius:_innerCircleRadius + (_outterCircleRadius - _innerCircleRadius)/2
borderWidth:_outterCircleRadius - _innerCircleRadius
CAShapeLayer *currentPieLayer = [self newCircleLayerWithRadius:_innerCircleRadius + (_outerCircleRadius - _innerCircleRadius)/2
borderWidth:_outerCircleRadius - _innerCircleRadius
fillColor:[UIColor clearColor]
borderColor:currentItem.color
startPercentage:startPercnetage
... ... @@ -117,7 +117,7 @@
- (UILabel *)descriptionLabelForItemAtIndex:(NSUInteger)index{
PNPieChartDataItem *currentDataItem = [self dataItemForIndex:index];
CGFloat distance = _innerCircleRadius + (_outterCircleRadius - _innerCircleRadius) / 2;
CGFloat distance = _innerCircleRadius + (_outerCircleRadius - _innerCircleRadius) / 2;
CGFloat centerPercentage =(_currentTotal + currentDataItem.value /2 ) / _total;
CGFloat rad = centerPercentage * 2 * M_PI;
... ... @@ -128,22 +128,22 @@
titleText = [NSString stringWithFormat:@"%.0f%%",currentDataItem.value/ _total * 100];
}
CGPoint center = CGPointMake(_outterCircleRadius + distance * sin(rad),
_outterCircleRadius - distance * cos(rad));
CGPoint center = CGPointMake(_outerCircleRadius + distance * sin(rad),
_outerCircleRadius - distance * cos(rad));
CGRect frame;
frame = CGRectMake(0, 0, 100, 80);
UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:frame];
[descriptionLabel setText:titleText];
[descriptionLabel setFont:_descriptionTextFont];
[descriptionLabel setTextColor:_descriptionTextColor];
[descriptionLabel setShadowColor:_descriptionTextShadowColor];
[descriptionLabel setShadowOffset:_descriptionTextShadowOffset];
[descriptionLabel setTextAlignment:NSTextAlignmentCenter];
[descriptionLabel setCenter:center];
[descriptionLabel setAlpha:0];
[descriptionLabel setBackgroundColor:[UIColor clearColor]];
descriptionLabel.text = titleText;
descriptionLabel.font = _descriptionTextFont;
descriptionLabel.textColor = _descriptionTextColor;
descriptionLabel.shadowColor = _descriptionTextShadowColor;
descriptionLabel.shadowOffset = _descriptionTextShadowOffset;
descriptionLabel.textAlignment = NSTextAlignmentCenter;
descriptionLabel.center = center;
descriptionLabel.alpha = 0;
descriptionLabel.backgroundColor = [UIColor clearColor];
return descriptionLabel;
}
... ... @@ -182,8 +182,8 @@
}
- (void)maskChart{
CAShapeLayer *maskLayer = [self newCircleLayerWithRadius:_innerCircleRadius + (_outterCircleRadius - _innerCircleRadius)/2
borderWidth:_outterCircleRadius - _innerCircleRadius
CAShapeLayer *maskLayer = [self newCircleLayerWithRadius:_innerCircleRadius + (_outerCircleRadius - _innerCircleRadius)/2
borderWidth:_outerCircleRadius - _innerCircleRadius
fillColor:[UIColor clearColor]
borderColor:[UIColor blackColor]
startPercentage:0
... ...
... ... @@ -21,7 +21,7 @@
+ (instancetype)dataItemWithValue:(CGFloat)value
color:(UIColor*)color
description:(NSString *)description{
description:(NSString *)description {
PNPieChartDataItem *item = [PNPieChartDataItem dataItemWithValue:value color:color];
item.textDescription = description;
return item;
... ...
... ... @@ -15,7 +15,7 @@
// Override point for customization after application launch.
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
... ... @@ -24,7 +24,7 @@
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
... ...
... ... @@ -10,5 +10,4 @@
@interface PCChartViewController : UIViewController
@end
... ...
... ... @@ -8,29 +8,6 @@
#import "PCChartViewController.h"
@interface PCChartViewController ()
@end
@implementation PCChartViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
... ...
... ... @@ -7,77 +7,44 @@
//
#import "PCChartsTableViewController.h"
#import "PNChart.h"
#import "PNLineChartData.h"
#import "PNLineChartDataItem.h"
@interface PCChartsTableViewController ()
@end
@implementation PCChartsTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
// In a story board-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
UIViewController * viewController = [segue destinationViewController];
if ([segue.identifier isEqualToString:@"lineChart"]) {
//Add LineChart
//Add line chart
UILabel * lineChartLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 90, SCREEN_WIDTH, 30)];
lineChartLabel.text = @"Line Chart";
lineChartLabel.textColor = PNFreshGreen;
lineChartLabel.font = [UIFont fontWithName:@"Avenir-Medium" size:23.0];
lineChartLabel.textAlignment = NSTextAlignmentCenter;
PNLineChart * lineChart = [[PNLineChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)];
lineChart.yLabelFormat = @"%1.1f";
lineChart.backgroundColor = [UIColor clearColor];
[lineChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5",@"SEP 6",@"SEP 7"]];
lineChart.showCoordinateAxis = YES;
// Line Chart Nr.1
// Line Chart #1
NSArray * data01Array = @[@60.1, @160.1, @126.4, @262.2, @186.2, @127.2, @176.2];
PNLineChartData *data01 = [PNLineChartData new];
data01.color = PNFreshGreen;
data01.itemCount = lineChart.xLabels.count;
data01.inflexionPointStyle = PNLineChartPointStyleCycle;
data01.inflexionPointStyle = PNLineChartPointStyleCircle;
data01.getData = ^(NSUInteger index) {
CGFloat yValue = [data01Array[index] floatValue];
return [PNLineChartDataItem dataItemWithY:yValue];
};
// Line Chart Nr.2
// Line Chart #2
NSArray * data02Array = @[@20.1, @180.1, @26.4, @202.2, @126.2, @167.2, @276.2];
PNLineChartData *data02 = [PNLineChartData new];
data02.color = PNTwitterColor;
... ... @@ -90,24 +57,24 @@
lineChart.chartData = @[data01, data02];
[lineChart strokeChart];
lineChart.delegate = self;
[viewController.view addSubview:lineChartLabel];
[viewController.view addSubview:lineChart];
viewController.title = @"Line Chart";
}else if ([segue.identifier isEqualToString:@"barChart"])
} else if ([segue.identifier isEqualToString:@"barChart"])
{
//Add BarChart
//Add bar chart
UILabel * barChartLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 90, SCREEN_WIDTH, 30)];
barChartLabel.text = @"Bar Chart";
barChartLabel.textColor = PNFreshGreen;
barChartLabel.font = [UIFont fontWithName:@"Avenir-Medium" size:23.0];
barChartLabel.textAlignment = NSTextAlignmentCenter;
self.barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)];
self.barChart.backgroundColor = [UIColor clearColor];
self.barChart.yLabelFormatter = ^(CGFloat yValue){
... ... @@ -123,106 +90,91 @@
self.barChart.barColorGradientStart = [UIColor blueColor];
[self.barChart strokeChart];
self.barChart.delegate = self;
[viewController.view addSubview:barChartLabel];
[viewController.view addSubview:self.barChart];
viewController.title = @"Bar Chart";
}else if ([segue.identifier isEqualToString:@"circleChart"])
} else if ([segue.identifier isEqualToString:@"circleChart"])
{
//Add CircleChart
//Add circle chart
UILabel * circleChartLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 90, SCREEN_WIDTH, 30)];
circleChartLabel.text = @"Circle Chart";
circleChartLabel.textColor = PNFreshGreen;
circleChartLabel.font = [UIFont fontWithName:@"Avenir-Medium" size:23.0];
circleChartLabel.textAlignment = NSTextAlignmentCenter;
PNCircleChart * circleChart = [[PNCircleChart alloc] initWithFrame:CGRectMake(0, 80.0, SCREEN_WIDTH, 100.0) andTotal:@100 andCurrent:@60 andClockwise:YES andShadow:YES];
PNCircleChart * circleChart = [[PNCircleChart alloc] initWithFrame:CGRectMake(0, 80.0, SCREEN_WIDTH, 100.0)
total:@100
current:@60
clockwise:YES
shadow:YES];
circleChart.backgroundColor = [UIColor clearColor];
[circleChart setStrokeColor:PNGreen];
[circleChart setStrokeColorGradientStart:[UIColor blueColor]];
[circleChart strokeChart];
[viewController.view addSubview:circleChartLabel];
[viewController.view addSubview:circleChart];
viewController.title = @"Circle Chart";
}else if ([segue.identifier isEqualToString:@"pieChart"])
} else if ([segue.identifier isEqualToString:@"pieChart"])
{
//Add PieChart
//Add pie chart
UILabel * pieChartLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 90, SCREEN_WIDTH, 30)];
pieChartLabel.text = @"Pie Chart";
pieChartLabel.textColor = PNFreshGreen;
pieChartLabel.font = [UIFont fontWithName:@"Avenir-Medium" size:23.0];
pieChartLabel.textAlignment = NSTextAlignmentCenter;
NSArray *items = @[[PNPieChartDataItem dataItemWithValue:10 color:PNLightGreen],
[PNPieChartDataItem dataItemWithValue:20 color:PNFreshGreen description:@"WWDC"],
[PNPieChartDataItem dataItemWithValue:40 color:PNDeepGreen description:@"GOOL I/O"],
[PNPieChartDataItem dataItemWithValue:40 color:PNDeepGreen description:@"GOOG I/O"],
];
PNPieChart *pieChart = [[PNPieChart alloc] initWithFrame:CGRectMake(40.0, 155.0, 240.0, 240.0) items:items];
pieChart.descriptionTextColor = [UIColor whiteColor];
pieChart.descriptionTextFont = [UIFont fontWithName:@"Avenir-Medium" size:14.0];
pieChart.descriptionTextShadowColor = [UIColor clearColor];
[pieChart strokeChart];
[viewController.view addSubview:pieChartLabel];
[viewController.view addSubview:pieChart];
viewController.title = @"Pie Chart";
}
}
-(void)userClickedOnLineKeyPoint:(CGPoint)point lineIndex:(NSInteger)lineIndex andPointIndex:(NSInteger)pointIndex{
- (void)userClickedOnLineKeyPoint:(CGPoint)point lineIndex:(NSInteger)lineIndex pointIndex:(NSInteger)pointIndex{
NSLog(@"Click Key on line %f, %f line index is %d and point index is %d",point.x, point.y,(int)lineIndex, (int)pointIndex);
}
-(void)userClickedOnLinePoint:(CGPoint)point lineIndex:(NSInteger)lineIndex{
- (void)userClickedOnLinePoint:(CGPoint)point lineIndex:(NSInteger)lineIndex{
NSLog(@"Click on line %f, %f, line index is %d",point.x, point.y, (int)lineIndex);
}
- (void)userClickedOnBarCharIndex:(NSInteger)barIndex
- (void)userClickedOnBarAtIndex:(NSInteger)barIndex
{
NSLog(@"Click on bar %@", @(barIndex));
PNBar * bar = [self.barChart.bars objectAtIndex:barIndex];
CABasicAnimation *animation= [CABasicAnimation animationWithKeyPath:@"transform.scale"];
animation.fromValue= @1.0;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
animation.fromValue = @1.0;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.toValue= @1.1;
animation.duration= 0.2;
animation.toValue = @1.1;
animation.duration = 0.2;
animation.repeatCount = 0;
animation.autoreverses = YES;
animation.removedOnCompletion = YES;
animation.fillMode=kCAFillModeForwards;
animation.fillMode = kCAFillModeForwards;
[bar.layer addAnimation:animation forKey:@"Float"];
}
... ...
... ... @@ -6,8 +6,6 @@
// Copyright (c) 2013年 kevinzhow. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "PCAppDelegate.h"
int main(int argc, char * argv[])
... ...
... ... @@ -107,9 +107,9 @@ NSArray *items = @[[PNPieChartDataItem dataItemWithValue:10 color:PNRed],
[PNPieChartDataItem dataItemWithValue:20 color:PNBlue description:@"WWDC"],
[PNPieChartDataItem dataItemWithValue:40 color:PNGreen description:@"GOOL I/O"],
];
PNPieChart *pieChart = [[PNPieChart alloc] initWithFrame:CGRectMake(40.0, 155.0, 240.0, 240.0) items:items];
pieChart.descriptionTextColor = [UIColor whiteColor];
pieChart.descriptionTextFont = [UIFont fontWithName:@"Avenir-Medium" size:14.0];
... ... @@ -135,7 +135,7 @@ lineChart.delegate = self;
//For DelegateMethod
-(void)userClickedOnLineKeyPoint:(CGPoint)point lineIndex:(NSInteger)lineIndex andPointIndex:(NSInteger)pointIndex{
-(void)userClickedOnLineKeyPoint:(CGPoint)point lineIndex:(NSInteger)lineIndex pointIndex:(NSInteger)pointIndex{
NSLog(@"Click Key on line %f, %f line index is %d and point index is %d",point.x, point.y,(int)lineIndex, (int)pointIndex);
}
... ...