Toggle navigation
Toggle navigation
This project
Loading...
Sign in
iOS
/
PNChart
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
kevinzhow
2015-01-13 12:15:42 +0800
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
85a87ab22a9326e770edfafe9e20eb0e94155a68
85a87ab2
2 parents
94674c59
b6036562
Merge branch 'master' of github.com:kevinzhow/PNChart
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
147 additions
and
57 deletions
PNChart/PNBarChart.m
PNChart/PNChartDelegate.h
PNChart/PNChartLabel.m
PNChart/PNCircleChart.h
PNChart/PNCircleChart.m
PNChart/PNLineChart.m
PNChart/PNLineChartData.m
PNChart/PNScatterChart.m
PNChart/PNScatterChartData.m
README.md
PNChart/PNBarChart.m
View file @
85a87ab
...
...
@@ -22,33 +22,47 @@
@implementation
PNBarChart
-
(
id
)
initWithCoder
:(
NSCoder
*
)
aDecoder
{
self
=
[
super
initWithCoder
:
aDecoder
];
if
(
self
)
{
[
self
setupDefaultValues
];
}
return
self
;
}
-
(
id
)
initWithFrame
:(
CGRect
)
frame
{
self
=
[
super
initWithFrame
:
frame
];
if
(
self
)
{
self
.
backgroundColor
=
[
UIColor
whiteColor
];
self
.
clipsToBounds
=
YES
;
_showLabel
=
YES
;
_barBackgroundColor
=
PNLightGrey
;
_labelTextColor
=
[
UIColor
grayColor
];
_labelFont
=
[
UIFont
systemFontOfSize
:
11
.
0
f
];
_xChartLabels
=
[
NSMutableArray
array
];
_yChartLabels
=
[
NSMutableArray
array
];
_bars
=
[
NSMutableArray
array
];
_xLabelSkip
=
1
;
_yLabelSum
=
4
;
_labelMarginTop
=
0
;
_chartMargin
=
15
.
0
;
_barRadius
=
2
.
0
;
_showChartBorder
=
NO
;
_yChartLabelWidth
=
18
;
_rotateForXAxisText
=
false
;
[
self
setupDefaultValues
];
}
return
self
;
}
-
(
void
)
setupDefaultValues
{
self
.
backgroundColor
=
[
UIColor
whiteColor
];
self
.
clipsToBounds
=
YES
;
_showLabel
=
YES
;
_barBackgroundColor
=
PNLightGrey
;
_labelTextColor
=
[
UIColor
grayColor
];
_labelFont
=
[
UIFont
systemFontOfSize
:
11
.
0
f
];
_xChartLabels
=
[
NSMutableArray
array
];
_yChartLabels
=
[
NSMutableArray
array
];
_bars
=
[
NSMutableArray
array
];
_xLabelSkip
=
1
;
_yLabelSum
=
4
;
_labelMarginTop
=
0
;
_chartMargin
=
15
.
0
;
_barRadius
=
2
.
0
;
_showChartBorder
=
NO
;
_yChartLabelWidth
=
18
;
_rotateForXAxisText
=
false
;
}
-
(
void
)
setYValues
:
(
NSArray
*
)
yValues
{
...
...
@@ -125,12 +139,12 @@
if
(
labelAddCount
==
_xLabelSkip
)
{
NSString
*
labelText
=
[
_xLabels
[
index
]
description
];
PNChartLabel
*
label
=
[[
PNChartLabel
alloc
]
initWithFrame
:
CGRect
Zero
];
PNChartLabel
*
label
=
[[
PNChartLabel
alloc
]
initWithFrame
:
CGRect
Make
(
0
,
0
,
_xLabelWidth
,
xLabelHeight
)
];
label
.
font
=
_labelFont
;
label
.
textColor
=
_labelTextColor
;
[
label
setTextAlignment
:
NSTextAlignmentCenter
];
label
.
text
=
labelText
;
[
label
sizeToFit
];
//
[label sizeToFit];
CGFloat
labelXPosition
;
if
(
_rotateForXAxisText
){
label
.
transform
=
CGAffineTransformMakeRotation
(
M_PI
/
4
);
...
...
PNChart/PNChartDelegate.h
View file @
85a87ab
...
...
@@ -9,7 +9,7 @@
#import <Foundation/Foundation.h>
@protocol
PNChartDelegate
<
NSObject
>
@optional
/**
* Callback method that gets invoked when the user taps on the chart line.
*/
...
...
@@ -27,4 +27,4 @@
*/
-
(
void
)
userClickedOnBarAtIndex
:(
NSInteger
)
barIndex
;
@end
\ No newline at end of file
@end
...
...
PNChart/PNChartLabel.m
View file @
85a87ab
...
...
@@ -19,8 +19,11 @@
self
.
backgroundColor
=
[
UIColor
clearColor
];
self
.
textAlignment
=
NSTextAlignmentCenter
;
self
.
userInteractionEnabled
=
YES
;
self
.
minimumScaleFactor
=
0
.
8
;
self
.
adjustsFontSizeToFitWidth
=
YES
;
self
.
numberOfLines
=
0
;
/* if you want to see ... in large labels un-comment this line
self.minimumScaleFactor = 0.8;
*/
}
return
self
;
...
...
PNChart/PNCircleChart.h
View file @
85a87ab
...
...
@@ -29,6 +29,30 @@ typedef NS_ENUM (NSUInteger, PNChartFormatType) {
clockwise
:(
BOOL
)
clockwise
shadow
:(
BOOL
)
hasBackgroundShadow
;
-
(
id
)
initWithFrame
:(
CGRect
)
frame
total
:(
NSNumber
*
)
total
current
:(
NSNumber
*
)
current
clockwise
:(
BOOL
)
clockwise
shadow
:(
BOOL
)
hasBackgroundShadow
shadowColor
:(
UIColor
*
)
backgroundShadowColor
;
-
(
id
)
initWithFrame
:(
CGRect
)
frame
total
:(
NSNumber
*
)
total
current
:(
NSNumber
*
)
current
clockwise
:(
BOOL
)
clockwise
shadow
:(
BOOL
)
hasBackgroundShadow
shadowColor
:(
UIColor
*
)
backgroundShadowColor
displayCountingLabel
:(
BOOL
)
displayCountingLabel
;
-
(
id
)
initWithFrame
:(
CGRect
)
frame
total
:(
NSNumber
*
)
total
current
:(
NSNumber
*
)
current
clockwise
:(
BOOL
)
clockwise
shadow
:(
BOOL
)
hasBackgroundShadow
shadowColor
:(
UIColor
*
)
backgroundShadowColor
displayCountingLabel
:(
BOOL
)
displayCountingLabel
overrideLineWidth
:(
NSNumber
*
)
overrideLineWidth
;
@property
(
strong
,
nonatomic
)
UICountingLabel
*
countingLabel
;
@property
(
nonatomic
)
UIColor
*
strokeColor
;
@property
(
nonatomic
)
UIColor
*
strokeColorGradientStart
;
...
...
@@ -43,4 +67,6 @@ typedef NS_ENUM (NSUInteger, PNChartFormatType) {
@property
(
nonatomic
)
CAShapeLayer
*
gradientMask
;
@property
(
nonatomic
)
CAShapeLayer
*
circleBackground
;
@property
(
nonatomic
)
BOOL
displayCountingLabel
;
@end
...
...
PNChart/PNCircleChart.m
View file @
85a87ab
...
...
@@ -13,12 +13,53 @@
@implementation
PNCircleChart
-
(
id
)
initWithFrame
:(
CGRect
)
frame
total
:(
NSNumber
*
)
total
current
:(
NSNumber
*
)
current
clockwise
:(
BOOL
)
clockwise
shadow
:(
BOOL
)
hasBackgroundShadow
{
return
[
self
initWithFrame
:
frame
total
:
total
current:
current
clockwise:
clockwise
shadow:
shadow
shadowColor:
PNGreen
displayCountingLabel:
YES
overrideLineWidth:
@8.0f
];
}
-
(
id
)
initWithFrame
:(
CGRect
)
frame
total
:(
NSNumber
*
)
total
current
:(
NSNumber
*
)
current
clockwise
:(
BOOL
)
clockwise
shadow
:(
BOOL
)
hasBackgroundShadow
shadowColor
:(
UIColor
*
)
backgroundShadowColor
{
return
[
self
initWithFrame
:
frame
total
:
total
current:
current
clockwise:
clockwise
shadow:
shadow
shadowColor:
backgroundShadowColor
displayCountingLabel:
YES
overrideLineWidth:
@8.0f
];
}
-
(
id
)
initWithFrame
:(
CGRect
)
frame
total
:(
NSNumber
*
)
total
current
:(
NSNumber
*
)
current
clockwise
:(
BOOL
)
clockwise
shadow
:(
BOOL
)
hasBackgroundShadow
shadowColor
:(
UIColor
*
)
backgroundShadowColor
displayCountingLabel
:(
BOOL
)
displayCountingLabel
{
return
[
self
initWithFrame
:
frame
total
:
total
current:
current
clockwise:
clockwise
shadow:
shadow
shadowColor:
PNGreen
displayCountingLabel:
displayCountingLabel
overrideLineWidth:
@8.0f
];
}
-
(
id
)
initWithFrame
:(
CGRect
)
frame
total
:(
NSNumber
*
)
total
current
:(
NSNumber
*
)
current
clockwise
:(
BOOL
)
clockwise
shadow
:(
BOOL
)
hasBackgroundShadow
shadowColor
:(
UIColor
*
)
backgroundShadowColor
displayCountingLabel
:(
BOOL
)
displayCountingLabel
overrideLineWidth
:(
NSNumber
*
)
overrideLineWidth
{
self
=
[
super
initWithFrame
:
frame
];
...
...
@@ -28,13 +69,16 @@
_strokeColor
=
PNFreshGreen
;
_duration
=
1
.
0
;
_chartType
=
PNChartFormatTypePercent
;
_displayCountingLabel
=
displayCountingLabel
;
CGFloat
startAngle
=
clockwise
?
-
90
.
0
f
:
270
.
0
f
;
CGFloat
endAngle
=
clockwise
?
-
90
.
01
f
:
270
.
01
f
;
_lineWidth
=
@8.0f
;
UIBezierPath
*
circlePath
=
[
UIBezierPath
bezierPathWithArcCenter
:
CGPointMake
(
self
.
center
.
x
,
self
.
center
.
y
)
radius
:(
self
.
frame
.
size
.
height
*
0
.
5
)
-
[
_lineWidth
floatValue
]
_lineWidth
=
overrideLineWidth
;
UIBezierPath
*
circlePath
=
[
UIBezierPath
bezierPathWithArcCenter
:
CGPointMake
(
self
.
bounds
.
size
.
width
/
2
.
0
f
,
self
.
bounds
.
size
.
height
/
2
.
0
f
)
radius
:(
self
.
frame
.
size
.
height
*
0
.
5
)
-
([
_lineWidth
floatValue
]
/
2
.
0
f
)
startAngle:
DEGREES_TO_RADIANS
(
startAngle
)
endAngle:
DEGREES_TO_RADIANS
(
endAngle
)
clockwise:
clockwise
];
...
...
@@ -51,7 +95,7 @@
_circleBackground
.
lineCap
=
kCALineCapRound
;
_circleBackground
.
fillColor
=
[
UIColor
clearColor
].
CGColor
;
_circleBackground
.
lineWidth
=
[
_lineWidth
floatValue
];
_circleBackground
.
strokeColor
=
(
hasBackgroundShadow
?
PNLightYellow
.
CGColor
:
[
UIColor
clearColor
].
CGColor
);
_circleBackground
.
strokeColor
=
(
hasBackgroundShadow
?
backgroundShadowColor
.
CGColor
:
[
UIColor
clearColor
].
CGColor
);
_circleBackground
.
strokeEnd
=
1
.
0
;
_circleBackground
.
zPosition
=
-
1
;
...
...
@@ -65,7 +109,9 @@
[
_countingLabel
setBackgroundColor
:[
UIColor
clearColor
]];
[
_countingLabel
setCenter
:
CGPointMake
(
self
.
center
.
x
,
self
.
center
.
y
)];
_countingLabel
.
method
=
UILabelCountingMethodEaseInOut
;
[
self
addSubview
:
_countingLabel
];;
if
(
_displayCountingLabel
)
{
[
self
addSubview
:
_countingLabel
];
}
}
return
self
;
...
...
@@ -76,21 +122,23 @@
{
// Add counting label
NSString
*
format
;
switch
(
self
.
chartType
)
{
case
PNChartFormatTypePercent
:
format
=
@"%d%%"
;
break
;
case
PNChartFormatTypeDollar
:
format
=
@"$%d"
;
break
;
case
PNChartFormatTypeNone
:
default
:
format
=
@"%d"
;
break
;
if
(
_displayCountingLabel
)
{
NSString
*
format
;
switch
(
self
.
chartType
)
{
case
PNChartFormatTypePercent
:
format
=
@"%d%%"
;
break
;
case
PNChartFormatTypeDollar
:
format
=
@"$%d"
;
break
;
case
PNChartFormatTypeNone
:
default
:
format
=
@"%d"
;
break
;
}
self
.
countingLabel
.
format
=
format
;
[
self
addSubview
:
self
.
countingLabel
];
}
self
.
countingLabel
.
format
=
format
;
[
self
addSubview
:
self
.
countingLabel
];
// Add circle params
...
...
@@ -172,7 +220,10 @@
}
[
_circle
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
[
self
.
countingLabel
countFrom
:
fmin
([
_current
floatValue
],
[
_total
floatValue
])
to
:
fmin
([
current
floatValue
],
[
_total
floatValue
])
withDuration
:
self
.
duration
];
if
(
_displayCountingLabel
)
{
[
self
.
countingLabel
countFrom
:
fmin
([
_current
floatValue
],
[
_total
floatValue
])
to
:
fmin
([
current
floatValue
],
[
_total
floatValue
])
withDuration
:
self
.
duration
];
}
_current
=
current
;
}
...
...
PNChart/PNLineChart.m
View file @
85a87ab
...
...
@@ -20,8 +20,6 @@
@property
(
nonatomic
)
NSMutableArray
*
chartPath
;
// Array of line path, one for each line.
@property
(
nonatomic
)
NSMutableArray
*
pointPath
;
// Array of point path, one for each line
-
(
void
)
setDefaultValues
;
@end
@implementation
PNLineChart
...
...
@@ -33,7 +31,7 @@
self
=
[
super
initWithCoder
:
coder
];
if
(
self
)
{
[
self
setDefaultValues
];
[
self
set
up
DefaultValues
];
}
return
self
;
...
...
@@ -44,7 +42,7 @@
self
=
[
super
initWithFrame
:
frame
];
if
(
self
)
{
[
self
setDefaultValues
];
[
self
set
up
DefaultValues
];
}
return
self
;
...
...
@@ -646,7 +644,7 @@
#pragma mark private methods
-
(
void
)
setDefaultValues
-
(
void
)
set
up
DefaultValues
{
// Initialization code
self
.
backgroundColor
=
[
UIColor
whiteColor
];
...
...
PNChart/PNLineChartData.m
View file @
85a87ab
...
...
@@ -11,13 +11,13 @@
{
self
=
[
super
init
];
if
(
self
)
{
[
self
setDefaultValues
];
[
self
set
up
DefaultValues
];
}
return
self
;
}
-
(
void
)
setDefaultValues
-
(
void
)
set
up
DefaultValues
{
_inflexionPointStyle
=
PNLineChartPointStyleNone
;
_inflexionPointWidth
=
6
.
f
;
...
...
PNChart/PNScatterChart.m
View file @
85a87ab
...
...
@@ -46,8 +46,6 @@
@property
(
nonatomic
)
BOOL
isForUpdate
;
-
(
void
)
setDefaultValues
;
@end
...
...
@@ -60,7 +58,7 @@
self
=
[
super
initWithCoder
:
coder
];
if
(
self
)
{
[
self
setDefaultValues
];
[
self
set
up
DefaultValues
];
}
return
self
;
}
...
...
@@ -70,7 +68,7 @@
self
=
[
super
initWithFrame
:
frame
];
if
(
self
)
{
[
self
setDefaultValues
];
[
self
set
up
DefaultValues
];
}
return
self
;
}
...
...
@@ -81,7 +79,7 @@
[
self
vectorYSetup
];
}
-
(
void
)
setDefaultValues
-
(
void
)
set
up
DefaultValues
{
// Initialization code
self
.
backgroundColor
=
[
UIColor
whiteColor
];
...
...
PNChart/PNScatterChartData.m
View file @
85a87ab
...
...
@@ -14,13 +14,13 @@
{
self
=
[
super
init
];
if
(
self
)
{
[
self
setDefaultValues
];
[
self
set
up
DefaultValues
];
}
return
self
;
}
-
(
void
)
setDefaultValues
-
(
void
)
set
up
DefaultValues
{
_inflexionPointStyle
=
PNScatterChartPointStyleCircle
;
_fillColor
=
[
UIColor
grayColor
];
...
...
README.md
View file @
85a87ab
...
...
@@ -88,7 +88,7 @@ PNBarChart * barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 135.0, S
//For Circle Chart
PNCircleChart
*
circleChart =
[
[PNCircleChart alloc
]
initWithFrame:CGRectMake(0, 80.0, SCREEN_WIDTH, 100.0)
andTotal:
[
NSNumber numberWithInt:100
]
andCurrent:
[
NSNumber numberWithInt:60
]
andClockwise
:NO];
PNCircleChart
*
circleChart =
[
[PNCircleChart alloc
]
initWithFrame:CGRectMake(0, 80.0, SCREEN_WIDTH, 100.0)
total:
[
NSNumber numberWithInt:100
]
current:
[
NSNumber numberWithInt:60
]
clockwise:NO shadow
:NO];
circleChart.backgroundColor =
[
UIColor clearColor
]
;
[
circleChart setStrokeColor:PNGreen
]
;
[
circleChart strokeChart
]
;
...
...
Please
register
or
login
to post a comment