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
2014-12-13 06:23:07 +0800
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
be9e6dd1d59fab55696eadc86df75427d8801815
be9e6dd1
2 parents
664b146f
1a13a562
Merge branch 'feature/dynamic_update_with_animate' into develop
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
445 additions
and
295 deletions
PNChart/PNBar.h
PNChart/PNBar.m
PNChart/PNBarChart.h
PNChart/PNBarChart.m
PNChart/PNCircleChart.h
PNChart/PNCircleChart.m
PNChart/PNLineChart.h
PNChart/PNLineChart.m
PNChartDemo/Base.lproj/Main.storyboard
PNChartDemo/PCChartViewController.h
PNChartDemo/PCChartViewController.m
PNChartDemo/PCChartsTableViewController.h
PNChartDemo/PCChartsTableViewController.m
PNChart/PNBar.h
View file @
be9e6dd
...
...
@@ -18,5 +18,6 @@
@property
(
nonatomic
)
UIColor
*
barColor
;
@property
(
nonatomic
)
UIColor
*
barColorGradientStart
;
@property
(
nonatomic
)
CGFloat
barRadius
;
@property
(
nonatomic
)
CAShapeLayer
*
gradientMask
;
@end
...
...
PNChart/PNBar.m
View file @
be9e6dd
...
...
@@ -38,7 +38,8 @@
-
(
void
)
setGrade
:(
float
)
grade
{
_grade
=
grade
;
NSLog
(
@"New garde %f"
,
grade
);
UIBezierPath
*
progressline
=
[
UIBezierPath
bezierPath
];
[
progressline
moveToPoint
:
CGPointMake
(
self
.
frame
.
size
.
width
/
2
.
0
,
self
.
frame
.
size
.
height
)];
...
...
@@ -46,7 +47,7 @@
[
progressline
setLineWidth
:
1
.
0
];
[
progressline
setLineCapStyle
:
kCGLineCapSquare
];
_chartLine
.
path
=
progressline
.
CGPath
;
if
(
_barColor
)
{
_chartLine
.
strokeColor
=
[
_barColor
CGColor
];
...
...
@@ -55,45 +56,69 @@
_chartLine
.
strokeColor
=
[
PNGreen
CGColor
];
}
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
pathAnimation
.
duration
=
1
.
0
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
pathAnimation
.
fromValue
=
@0.0f
;
pathAnimation
.
toValue
=
@1.0f
;
[
_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
=
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
);
gradientLayer
.
frame
=
CGRectMake
(
0
,
0
,
self
.
bounds
.
size
.
width
,
self
.
bounds
.
size
.
height
);
UIColor
*
endColor
=
(
_barColor
?
_barColor
:
[
UIColor
greenColor
]);
NSArray
*
colors
=
@[
(
id
)
_barColorGradientStart
.
CGColor
,
(
id
)
endColor
.
CGColor
];
gradientLayer
.
colors
=
colors
;
[
gradientLayer
setMask
:
gradientMask
];
[
_chartLine
addSublayer
:
gradientLayer
];
gradientMask
.
strokeEnd
=
1
.
0
;
[
gradientMask
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
if
(
_grade
)
{
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"path"
];
pathAnimation
.
fromValue
=
(
id
)
_chartLine
.
path
;
pathAnimation
.
toValue
=
(
id
)[
progressline
CGPath
];
pathAnimation
.
duration
=
0
.
5
f
;
pathAnimation
.
autoreverses
=
NO
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
[
_chartLine
addAnimation
:
pathAnimation
forKey
:
@"animationKey"
];
_chartLine
.
path
=
progressline
.
CGPath
;
if
(
_barColorGradientStart
)
{
// Add gradient
[
self
.
gradientMask
addAnimation
:
pathAnimation
forKey
:
@"animationKey"
];
self
.
gradientMask
.
path
=
progressline
.
CGPath
;
}
}
else
{
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
pathAnimation
.
duration
=
1
.
0
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
pathAnimation
.
fromValue
=
@0.0f
;
pathAnimation
.
toValue
=
@1.0f
;
[
_chartLine
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
_chartLine
.
strokeEnd
=
1
.
0
;
_chartLine
.
path
=
progressline
.
CGPath
;
// Check if user wants to add a gradient from the start color to the bar color
if
(
_barColorGradientStart
)
{
// Add gradient
self
.
gradientMask
=
[
CAShapeLayer
layer
];
self
.
gradientMask
.
fillColor
=
[[
UIColor
clearColor
]
CGColor
];
self
.
gradientMask
.
strokeColor
=
[[
UIColor
blackColor
]
CGColor
];
self
.
gradientMask
.
lineWidth
=
self
.
frame
.
size
.
width
;
self
.
gradientMask
.
frame
=
CGRectMake
(
0
,
0
,
self
.
bounds
.
size
.
width
,
self
.
bounds
.
size
.
height
);
self
.
gradientMask
.
path
=
progressline
.
CGPath
;
CAGradientLayer
*
gradientLayer
=
[
CAGradientLayer
layer
];
gradientLayer
.
startPoint
=
CGPointMake
(
0
.
5
,
1
.
0
);
gradientLayer
.
endPoint
=
CGPointMake
(
0
.
5
,
0
.
0
);
gradientLayer
.
frame
=
CGRectMake
(
0
,
0
,
self
.
bounds
.
size
.
width
,
self
.
bounds
.
size
.
height
);
UIColor
*
endColor
=
(
_barColor
?
_barColor
:
[
UIColor
greenColor
]);
NSArray
*
colors
=
@[
(
id
)
_barColorGradientStart
.
CGColor
,
(
id
)
endColor
.
CGColor
];
gradientLayer
.
colors
=
colors
;
[
gradientLayer
setMask
:
self
.
gradientMask
];
[
_chartLine
addSublayer
:
gradientLayer
];
self
.
gradientMask
.
strokeEnd
=
1
.
0
;
[
self
.
gradientMask
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
}
}
_grade
=
grade
;
}
...
...
PNChart/PNBarChart.h
View file @
be9e6dd
...
...
@@ -36,6 +36,9 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue);
@property
(
nonatomic
)
NSArray
*
strokeColors
;
/** Update Values. */
-
(
void
)
updateChartData
:(
NSArray
*
)
data
;
/** Changes chart margin. */
@property
(
nonatomic
)
CGFloat
yChartLabelWidth
;
...
...
PNChart/PNBarChart.m
View file @
be9e6dd
...
...
@@ -12,7 +12,8 @@
@interface
PNBarChart
()
{
NSMutableArray
*
_labels
;
NSMutableArray
*
_xChartLabels
;
NSMutableArray
*
_yChartLabels
;
}
-
(
UIColor
*
)
barColorAtIndex
:
(
NSUInteger
)
index
;
...
...
@@ -32,7 +33,8 @@
_barBackgroundColor
=
PNLightGrey
;
_labelTextColor
=
[
UIColor
grayColor
];
_labelFont
=
[
UIFont
systemFontOfSize
:
11
.
0
f
];
_labels
=
[
NSMutableArray
array
];
_xChartLabels
=
[
NSMutableArray
array
];
_yChartLabels
=
[
NSMutableArray
array
];
_bars
=
[
NSMutableArray
array
];
_xLabelSkip
=
1
;
_yLabelSum
=
4
;
...
...
@@ -57,9 +59,41 @@
}
else
{
[
self
getYValueMax
:
yValues
];
}
if
(
_yChartLabels
)
{
[
self
viewCleanupForCollection
:
_yChartLabels
];
}
else
{
_yLabels
=
[
NSMutableArray
new
];
}
if
(
_showLabel
)
{
//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
,
yLabelHeight
)];
label
.
font
=
_labelFont
;
label
.
textColor
=
_labelTextColor
;
[
label
setTextAlignment
:
NSTextAlignmentRight
];
label
.
text
=
labelText
;
[
_yChartLabels
addObject
:
label
];
[
self
addSubview
:
label
];
}
}
}
_xLabelWidth
=
(
self
.
frame
.
size
.
width
-
_chartMargin
*
2
)
/
[
_yValues
count
];
-
(
void
)
updateChartData
:(
NSArray
*
)
data
{
self
.
yValues
=
data
;
[
self
updateBar
];
}
-
(
void
)
getYValueMax
:(
NSArray
*
)
yLabels
...
...
@@ -76,29 +110,19 @@
-
(
void
)
setXLabels
:(
NSArray
*
)
xLabels
{
_xLabels
=
xLabels
;
if
(
_showLabel
)
{
_xLabelWidth
=
(
self
.
frame
.
size
.
width
-
_chartMargin
*
2
)
/
[
xLabels
count
];
if
(
_xChartLabels
)
{
[
self
viewCleanupForCollection
:
_xChartLabels
];
}
else
{
_xChartLabels
=
[
NSMutableArray
new
];
}
}
-
(
void
)
setStrokeColor
:(
UIColor
*
)
strokeColor
{
_strokeColor
=
strokeColor
;
}
-
(
void
)
strokeChart
{
[
self
viewCleanupForCollection
:
_labels
];
//Add Labels
if
(
_showLabel
)
{
//Add x labels
_xLabelWidth
=
(
self
.
frame
.
size
.
width
-
_chartMargin
*
2
)
/
[
xLabels
count
];
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
];
...
...
@@ -118,106 +142,104 @@
label
.
center
=
CGPointMake
(
labelXPosition
,
self
.
frame
.
size
.
height
-
xLabelHeight
-
_chartMargin
+
label
.
frame
.
size
.
height
/
2
.
0
+
_labelMarginTop
);
labelAddCount
=
0
;
[
_
l
abels
addObject
:
label
];
[
_
xChartL
abels
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
,
yLabelHeight
)];
label
.
font
=
_labelFont
;
label
.
textColor
=
_labelTextColor
;
[
label
setTextAlignment
:
NSTextAlignmentRight
];
label
.
text
=
labelText
;
[
_labels
addObject
:
label
];
[
self
addSubview
:
label
];
}
}
}
[
self
viewCleanupForCollection
:
_bars
];
-
(
void
)
setStrokeColor
:(
UIColor
*
)
strokeColor
{
_strokeColor
=
strokeColor
;
}
-
(
void
)
updateBar
{
//Add bars
CGFloat
chartCavanHeight
=
self
.
frame
.
size
.
height
-
_chartMargin
*
2
-
xLabelHeight
;
NSInteger
index
=
0
;
for
(
NSNumber
*
valueString
in
_yValues
)
{
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
;
if
(
_bars
.
count
==
_yValues
.
count
)
{
bar
=
[
_bars
objectAtIndex
:
index
];
}
else
{
barXPosition
=
index
*
_xLabelWidth
+
_chartMargin
+
_xLabelWidth
*
0
.
25
;
if
(
_showLabel
)
{
barWidth
=
_xLabelWidth
*
0
.
5
;
CGFloat
barWidth
;
CGFloat
barXPosition
;
if
(
_barWidth
)
{
barWidth
=
_barWidth
;
barXPosition
=
index
*
_xLabelWidth
+
_chartMargin
+
_xLabelWidth
/
2
.
0
-
_barWidth
/
2
.
0
;
}
else
{
barXPosition
=
index
*
_xLabelWidth
+
_chartMargin
+
_xLabelWidth
*
0
.
25
;
if
(
_showLabel
)
{
barWidth
=
_xLabelWidth
*
0
.
5
;
}
else
{
barWidth
=
_xLabelWidth
*
0
.
6
;
}
}
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
];
}
// Add gradient
bar
.
barColorGradientStart
=
_barColorGradientStart
;
//For Click Index
bar
.
tag
=
index
;
[
_bars
addObject
:
bar
];
[
self
addSubview
:
bar
];
}
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
float
value
=
[
valueString
floatValue
];
float
grade
=
(
float
)
value
/
(
float
)
_yValueMax
;
if
(
isnan
(
grade
))
{
grade
=
0
;
}
bar
.
grade
=
grade
;
index
+=
1
;
}
}
// Add gradient
bar
.
barColorGradientStart
=
_barColorGradientStart
;
//For Click Index
bar
.
tag
=
index
;
-
(
void
)
strokeChart
{
//Add Labels
[
_bars
addObject
:
bar
];
[
self
addSubview
:
bar
];
[
self
viewCleanupForCollection
:
_bars
];
index
+=
1
;
}
//Update Bar
[
self
updateBar
];
//Add chart border lines
if
(
_showChartBorder
)
{
...
...
PNChart/PNCircleChart.h
View file @
be9e6dd
...
...
@@ -22,6 +22,7 @@ typedef NS_ENUM (NSUInteger, PNChartFormatType) {
-
(
void
)
strokeChart
;
-
(
void
)
growChartByAmount
:(
NSNumber
*
)
growAmount
;
-
(
void
)
updateChartByCurrent
:(
NSNumber
*
)
current
;
-
(
id
)
initWithFrame
:(
CGRect
)
frame
total
:(
NSNumber
*
)
total
current
:(
NSNumber
*
)
current
...
...
@@ -37,7 +38,9 @@ typedef NS_ENUM (NSUInteger, PNChartFormatType) {
@property
(
nonatomic
)
NSTimeInterval
duration
;
@property
(
nonatomic
)
PNChartFormatType
chartType
;
@property
(
nonatomic
)
CAShapeLayer
*
circle
;
@property
(
nonatomic
)
CAShapeLayer
*
gradientMask
;
@property
(
nonatomic
)
CAShapeLayer
*
circleBackground
;
@end
...
...
PNChart/PNCircleChart.m
View file @
be9e6dd
...
...
@@ -116,14 +116,14 @@
if
(
_strokeColorGradientStart
)
{
// Add gradient
CAShapeLayer
*
gradientMask
=
[
CAShapeLayer
layer
];
gradientMask
.
fillColor
=
[[
UIColor
clearColor
]
CGColor
];
gradientMask
.
strokeColor
=
[[
UIColor
blackColor
]
CGColor
];
gradientMask
.
lineWidth
=
_circle
.
lineWidth
;
gradientMask
.
lineCap
=
kCALineCapRound
;
self
.
gradientMask
=
[
CAShapeLayer
layer
];
self
.
gradientMask
.
fillColor
=
[[
UIColor
clearColor
]
CGColor
];
self
.
gradientMask
.
strokeColor
=
[[
UIColor
blackColor
]
CGColor
];
self
.
gradientMask
.
lineWidth
=
_circle
.
lineWidth
;
self
.
gradientMask
.
lineCap
=
kCALineCapRound
;
CGRect
gradientFrame
=
CGRectMake
(
0
,
0
,
2
*
self
.
bounds
.
size
.
width
,
2
*
self
.
bounds
.
size
.
height
);
gradientMask
.
frame
=
gradientFrame
;
gradientMask
.
path
=
_circle
.
path
;
self
.
gradientMask
.
frame
=
gradientFrame
;
self
.
gradientMask
.
path
=
_circle
.
path
;
CAGradientLayer
*
gradientLayer
=
[
CAGradientLayer
layer
];
gradientLayer
.
startPoint
=
CGPointMake
(
0
.
5
,
1
.
0
);
...
...
@@ -136,13 +136,13 @@
];
gradientLayer
.
colors
=
colors
;
[
gradientLayer
setMask
:
gradientMask
];
[
gradientLayer
setMask
:
self
.
gradientMask
];
[
_circle
addSublayer
:
gradientLayer
];
gradientMask
.
strokeEnd
=
[
_current
floatValue
]
/
[
_total
floatValue
];
self
.
gradientMask
.
strokeEnd
=
[
_current
floatValue
]
/
[
_total
floatValue
];
[
gradientMask
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
[
self
.
gradientMask
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
}
}
...
...
@@ -153,16 +153,27 @@
NSNumber
*
updatedValue
=
[
NSNumber
numberWithFloat
:[
_current
floatValue
]
+
[
growAmount
floatValue
]];
// Add animation
[
self
updateChartByCurrent
:
updatedValue
];
}
-
(
void
)
updateChartByCurrent
:
(
NSNumber
*
)
current
{
// Add animation
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
pathAnimation
.
duration
=
self
.
duration
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
pathAnimation
.
fromValue
=
@
([
_current
floatValue
]
/
[
_total
floatValue
]);
pathAnimation
.
toValue
=
@
([
updatedValue
floatValue
]
/
[
_total
floatValue
]);
_circle
.
strokeEnd
=
[
updatedValue
floatValue
]
/
[
_total
floatValue
];
pathAnimation
.
toValue
=
@
([
current
floatValue
]
/
[
_total
floatValue
]);
_circle
.
strokeEnd
=
[
current
floatValue
]
/
[
_total
floatValue
];
if
(
_strokeColorGradientStart
)
{
self
.
gradientMask
.
strokeEnd
=
_circle
.
strokeEnd
;
[
self
.
gradientMask
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
}
[
_circle
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
[
self
.
countingLabel
countFrom
:
fmin
([
_current
floatValue
],
[
_total
floatValue
])
to
:
fmin
([
_current
floatValue
]
+
[
growAmou
nt
floatValue
],
[
_total
floatValue
])
withDuration
:
self
.
duration
];
_current
=
updatedValue
;
[
self
.
countingLabel
countFrom
:
fmin
([
_current
floatValue
],
[
_total
floatValue
])
to
:
fmin
([
curre
nt
floatValue
],
[
_total
floatValue
])
withDuration
:
self
.
duration
];
_current
=
current
;
}
@end
...
...
PNChart/PNLineChart.h
View file @
be9e6dd
...
...
@@ -28,10 +28,15 @@
@property
(
nonatomic
)
NSArray
*
chartData
;
@property
(
nonatomic
)
NSMutableArray
*
pathPoints
;
@property
(
nonatomic
)
NSMutableArray
*
xChartLabels
;
@property
(
nonatomic
)
NSMutableArray
*
yChartLabels
;
@property
(
nonatomic
)
CGFloat
xLabelWidth
;
@property
(
nonatomic
)
UIFont
*
xLabelFont
;
@property
(
nonatomic
)
UIColor
*
xLabelColor
;
@property
(
nonatomic
)
CGFloat
yValueMax
;
@property
(
nonatomic
)
CGFloat
yFixedValueMax
;
@property
(
nonatomic
)
CGFloat
yFixedValueMin
;
@property
(
nonatomic
)
CGFloat
yValueMin
;
@property
(
nonatomic
)
NSInteger
yLabelNum
;
@property
(
nonatomic
)
CGFloat
yLabelHeight
;
...
...
@@ -59,4 +64,10 @@
-
(
void
)
setXLabels
:(
NSArray
*
)
xLabels
withWidth
:(
CGFloat
)
width
;
/**
* Update Chart Value
*/
-
(
void
)
updateChartData
:(
NSArray
*
)
data
;
@end
...
...
PNChart/PNLineChart.m
View file @
be9e6dd
This diff is collapsed. Click to expand it.
PNChartDemo/Base.lproj/Main.storyboard
View file @
be9e6dd
...
...
@@ -22,15 +22,30 @@
<state
key=
"normal"
title=
"Change Value"
>
<color
key=
"titleShadowColor"
white=
"0.5"
alpha=
"1"
colorSpace=
"calibratedWhite"
/>
</state>
<connections>
<action
selector=
"changeValue:"
destination=
"Tha-Wr-sPW"
eventType=
"touchUpInside"
id=
"zeG-Cp-Wjs"
/>
</connections>
</button>
<label
opaque=
"NO"
userInteractionEnabled=
"NO"
contentMode=
"left"
horizontalHuggingPriority=
"251"
verticalHuggingPriority=
"251"
misplaced=
"YES"
text=
"Label"
textAlignment=
"center"
lineBreakMode=
"tailTruncation"
baselineAdjustment=
"alignBaselines"
adjustsFontSizeToFit=
"NO"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"FUU-vZ-jMd"
>
<rect
key=
"frame"
x=
"53"
y=
"81"
width=
"215"
height=
"30"
/>
<fontDescription
key=
"fontDescription"
name=
"Avenir-Medium"
family=
"Avenir"
pointSize=
"23"
/>
<color
key=
"textColor"
cocoaTouchSystemColor=
"darkTextColor"
/>
<nil
key=
"highlightedColor"
/>
</label>
</subviews>
<color
key=
"backgroundColor"
white=
"1"
alpha=
"1"
colorSpace=
"custom"
customColorSpace=
"calibratedWhite"
/>
<constraints>
<constraint
firstItem=
"FUU-vZ-jMd"
firstAttribute=
"top"
secondItem=
"znr-YO-4a4"
secondAttribute=
"bottom"
constant=
"17"
id=
"DLv-qJ-h7R"
/>
<constraint
firstAttribute=
"centerX"
secondItem=
"FUU-vZ-jMd"
secondAttribute=
"centerX"
id=
"YGT-a5-Zka"
/>
<constraint
firstItem=
"L3F-13-Wf5"
firstAttribute=
"top"
secondItem=
"znr-YO-4a4"
secondAttribute=
"bottom"
constant=
"300"
id=
"ewm-kv-p8k"
/>
<constraint
firstAttribute=
"centerX"
secondItem=
"L3F-13-Wf5"
secondAttribute=
"centerX"
id=
"zXw-WV-mro"
/>
</constraints>
</view>
<navigationItem
key=
"navigationItem"
title=
"PNChart"
id=
"Ukg-Sg-E2z"
/>
<connections>
<outlet
property=
"changeValueButton"
destination=
"L3F-13-Wf5"
id=
"JnI-y3-Xpj"
/>
<outlet
property=
"titleLabel"
destination=
"FUU-vZ-jMd"
id=
"dA3-KC-Ht4"
/>
</connections>
</viewController>
<placeholder
placeholderIdentifier=
"IBFirstResponder"
id=
"kDa-u3-t6i"
userLabel=
"First Responder"
sceneMemberID=
"firstResponder"
/>
</objects>
...
...
PNChartDemo/PCChartViewController.h
View file @
be9e6dd
...
...
@@ -7,7 +7,19 @@
//
#import <UIKit/UIKit.h>
#import "PNChartDelegate.h"
#import "PNChart.h"
@interface
PCChartViewController
:
UIViewController
@interface
PCChartViewController
:
UIViewController
<
PNChartDelegate
>
@property
(
nonatomic
)
PNLineChart
*
lineChart
;
@property
(
nonatomic
)
PNBarChart
*
barChart
;
@property
(
nonatomic
)
PNCircleChart
*
circleChart
;
@property
(
nonatomic
)
PNPieChart
*
pieChart
;
@property
(
weak
,
nonatomic
)
IBOutlet
UILabel
*
titleLabel
;
-
(
IBAction
)
changeValue
:(
id
)
sender
;
@property
(
weak
,
nonatomic
)
IBOutlet
UIButton
*
changeValueButton
;
@end
...
...
PNChartDemo/PCChartViewController.m
View file @
be9e6dd
...
...
@@ -10,4 +10,189 @@
@implementation
PCChartViewController
-
(
void
)
viewDidLoad
{
[
super
viewDidLoad
];
self
.
titleLabel
.
textColor
=
PNFreshGreen
;
if
([
self
.
title
isEqualToString
:
@"Line Chart"
])
{
self
.
titleLabel
.
text
=
@"Line Chart"
;
self
.
lineChart
=
[[
PNLineChart
alloc
]
initWithFrame
:
CGRectMake
(
0
,
135
.
0
,
SCREEN_WIDTH
,
200
.
0
)];
self
.
lineChart
.
yLabelFormat
=
@"%1.1f"
;
self
.
lineChart
.
backgroundColor
=
[
UIColor
clearColor
];
[
self
.
lineChart
setXLabels
:@[
@"SEP 1"
,
@"SEP 2"
,
@"SEP 3"
,
@"SEP 4"
,
@"SEP 5"
,
@"SEP 6"
,
@"SEP 7"
]];
self
.
lineChart
.
showCoordinateAxis
=
YES
;
//Use yFixedValueMax and yFixedValueMin to Fix the Max and Min Y Value
//Only if you needed
self
.
lineChart
.
yFixedValueMax
=
500
.
0
;
self
.
lineChart
.
yFixedValueMin
=
1
.
0
;
// 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
=
data01Array
.
count
;
data01
.
inflexionPointStyle
=
PNLineChartPointStyleTriangle
;
data01
.
getData
=
^
(
NSUInteger
index
)
{
CGFloat
yValue
=
[
data01Array
[
index
]
floatValue
];
return
[
PNLineChartDataItem
dataItemWithY
:
yValue
];
};
// 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
;
data02
.
itemCount
=
data02Array
.
count
;
data02
.
inflexionPointStyle
=
PNLineChartPointStyleSquare
;
data02
.
getData
=
^
(
NSUInteger
index
)
{
CGFloat
yValue
=
[
data02Array
[
index
]
floatValue
];
return
[
PNLineChartDataItem
dataItemWithY
:
yValue
];
};
self
.
lineChart
.
chartData
=
@[
data01
,
data02
];
[
self
.
lineChart
strokeChart
];
self
.
lineChart
.
delegate
=
self
;
[
self
.
view
addSubview
:
self
.
lineChart
];
}
else
if
([
self
.
title
isEqualToString
:
@"Bar Chart"
])
{
self
.
titleLabel
.
text
=
@"Bar Chart"
;
self
.
barChart
=
[[
PNBarChart
alloc
]
initWithFrame
:
CGRectMake
(
0
,
135
.
0
,
SCREEN_WIDTH
,
200
.
0
)];
self
.
barChart
.
backgroundColor
=
[
UIColor
clearColor
];
self
.
barChart
.
yLabelFormatter
=
^
(
CGFloat
yValue
){
CGFloat
yValueParsed
=
yValue
;
NSString
*
labelText
=
[
NSString
stringWithFormat
:
@"%1.f"
,
yValueParsed
];
return
labelText
;
};
self
.
barChart
.
labelMarginTop
=
5
.
0
;
[
self
.
barChart
setXLabels
:@[
@"SEP 1"
,
@"SEP 2"
,
@"SEP 3"
,
@"SEP 4"
,
@"SEP 5"
,
@"SEP 6"
,
@"SEP 7"
]];
self
.
barChart
.
rotateForXAxisText
=
true
;
[
self
.
barChart
setYValues
:@[
@1
,
@24
,
@12
,
@18
,
@30
,
@10
,
@21
]];
[
self
.
barChart
setStrokeColors
:@[
PNGreen
,
PNGreen
,
PNRed
,
PNGreen
,
PNGreen
,
PNYellow
,
PNGreen
]];
// Adding gradient
self
.
barChart
.
barColorGradientStart
=
[
UIColor
blueColor
];
[
self
.
barChart
strokeChart
];
self
.
barChart
.
delegate
=
self
;
[
self
.
view
addSubview
:
self
.
barChart
];
}
else
if
([
self
.
title
isEqualToString
:
@"Circle Chart"
])
{
self
.
titleLabel
.
text
=
@"Circle Chart"
;
self
.
circleChart
=
[[
PNCircleChart
alloc
]
initWithFrame
:
CGRectMake
(
0
,
80
.
0
,
SCREEN_WIDTH
,
100
.
0
)
total
:
@100
current
:
@60
clockwise
:
YES
shadow
:
YES
];
self
.
circleChart
.
backgroundColor
=
[
UIColor
clearColor
];
[
self
.
circleChart
setStrokeColor
:
PNGreen
];
[
self
.
circleChart
setStrokeColorGradientStart
:[
UIColor
blueColor
]];
[
self
.
circleChart
strokeChart
];
[
self
.
view
addSubview
:
self
.
circleChart
];
}
else
if
([
self
.
title
isEqualToString
:
@"Pie Chart"
])
{
self
.
titleLabel
.
text
=
@"Pie Chart"
;
NSArray
*
items
=
@[[
PNPieChartDataItem
dataItemWithValue
:
10
color
:
PNLightGreen
],
[
PNPieChartDataItem
dataItemWithValue
:
20
color
:
PNFreshGreen
description
:
@"WWDC"
],
[
PNPieChartDataItem
dataItemWithValue
:
40
color
:
PNDeepGreen
description
:
@"GOOG I/O"
],
];
self
.
pieChart
=
[[
PNPieChart
alloc
]
initWithFrame
:
CGRectMake
(
SCREEN_WIDTH
/
2
.
0
-
100
,
135
,
200
.
0
,
200
.
0
)
items
:
items
];
self
.
pieChart
.
descriptionTextColor
=
[
UIColor
whiteColor
];
self
.
pieChart
.
descriptionTextFont
=
[
UIFont
fontWithName
:
@"Avenir-Medium"
size
:
11
.
0
];
self
.
pieChart
.
descriptionTextShadowColor
=
[
UIColor
clearColor
];
[
self
.
pieChart
strokeChart
];
[
self
.
view
addSubview
:
self
.
pieChart
];
self
.
changeValueButton
.
hidden
=
YES
;
}
}
-
(
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
{
NSLog
(
@"Click on line %f, %f, line index is %d"
,
point
.
x
,
point
.
y
,
(
int
)
lineIndex
);
}
-
(
IBAction
)
changeValue
:
(
id
)
sender
{
if
([
self
.
title
isEqualToString
:
@"Line Chart"
])
{
// Line Chart #1
NSArray
*
data01Array
=
@[
@
(
arc4random
()
%
300
),
@
(
arc4random
()
%
300
),
@
(
arc4random
()
%
300
),
@
(
arc4random
()
%
300
),
@
(
arc4random
()
%
300
),
@
(
arc4random
()
%
300
),
@
(
arc4random
()
%
300
)];
PNLineChartData
*
data01
=
[
PNLineChartData
new
];
data01
.
color
=
PNFreshGreen
;
data01
.
itemCount
=
data01Array
.
count
;
data01
.
inflexionPointStyle
=
PNLineChartPointStyleTriangle
;
data01
.
getData
=
^
(
NSUInteger
index
)
{
CGFloat
yValue
=
[
data01Array
[
index
]
floatValue
];
return
[
PNLineChartDataItem
dataItemWithY
:
yValue
];
};
// Line Chart #2
NSArray
*
data02Array
=
@[
@
(
arc4random
()
%
300
),
@
(
arc4random
()
%
300
),
@
(
arc4random
()
%
300
),
@
(
arc4random
()
%
300
),
@
(
arc4random
()
%
300
),
@
(
arc4random
()
%
300
),
@
(
arc4random
()
%
300
)];
PNLineChartData
*
data02
=
[
PNLineChartData
new
];
data02
.
color
=
PNTwitterColor
;
data02
.
itemCount
=
data02Array
.
count
;
data02
.
inflexionPointStyle
=
PNLineChartPointStyleSquare
;
data02
.
getData
=
^
(
NSUInteger
index
)
{
CGFloat
yValue
=
[
data02Array
[
index
]
floatValue
];
return
[
PNLineChartDataItem
dataItemWithY
:
yValue
];
};
[
self
.
lineChart
setXLabels
:@[
@"DEC 1"
,
@"DEC 2"
,
@"DEC 3"
,
@"DEC 4"
,
@"DEC 5"
,
@"DEC 6"
,
@"DEC 7"
]];
[
self
.
lineChart
updateChartData
:@[
data01
,
data02
]];
}
else
if
([
self
.
title
isEqualToString
:
@"Bar Chart"
])
{
[
self
.
barChart
setXLabels
:@[
@"Jan 1"
,
@"Jan 2"
,
@"Jan 3"
,
@"Jan 4"
,
@"Jan 5"
,
@"Jan 6"
,
@"Jan 7"
]];
[
self
.
barChart
updateChartData
:@[
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
),
@
(
arc4random
()
%
30
)]];
}
else
if
([
self
.
title
isEqualToString
:
@"Circle Chart"
])
{
[
self
.
circleChart
updateChartByCurrent
:
@
(
arc4random
()
%
100
)];
}
}
-
(
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
;
animation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
animation
.
toValue
=
@1.1
;
animation
.
duration
=
0
.
2
;
animation
.
repeatCount
=
0
;
animation
.
autoreverses
=
YES
;
animation
.
removedOnCompletion
=
YES
;
animation
.
fillMode
=
kCAFillModeForwards
;
[
bar
.
layer
addAnimation
:
animation
forKey
:
@"Float"
];
}
@end
...
...
PNChartDemo/PCChartsTableViewController.h
View file @
be9e6dd
...
...
@@ -7,11 +7,7 @@
//
#import <UIKit/UIKit.h>
#import "PNChartDelegate.h"
#import "PNChart.h"
@interface
PCChartsTableViewController
:
UITableViewController
<
PNChartDelegate
>
@property
(
nonatomic
)
PNBarChart
*
barChart
;
@interface
PCChartsTableViewController
:
UITableViewController
@end
...
...
PNChartDemo/PCChartsTableViewController.m
View file @
be9e6dd
...
...
@@ -21,47 +21,6 @@
if
([
segue
.
identifier
isEqualToString
:
@"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 #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
=
PNLineChartPointStyleTriangle
;
data01
.
getData
=
^
(
NSUInteger
index
)
{
CGFloat
yValue
=
[
data01Array
[
index
]
floatValue
];
return
[
PNLineChartDataItem
dataItemWithY
:
yValue
];
};
// 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
;
data02
.
itemCount
=
lineChart
.
xLabels
.
count
;
data02
.
inflexionPointStyle
=
PNLineChartPointStyleSquare
;
data02
.
getData
=
^
(
NSUInteger
index
)
{
CGFloat
yValue
=
[
data02Array
[
index
]
floatValue
];
return
[
PNLineChartDataItem
dataItemWithY
:
yValue
];
};
lineChart
.
chartData
=
@[
data01
,
data02
];
[
lineChart
strokeChart
];
lineChart
.
delegate
=
self
;
[
viewController
.
view
addSubview
:
lineChartLabel
];
[
viewController
.
view
addSubview
:
lineChart
];
viewController
.
title
=
@"Line Chart"
;
...
...
@@ -69,114 +28,21 @@
{
//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
){
CGFloat
yValueParsed
=
yValue
;
NSString
*
labelText
=
[
NSString
stringWithFormat
:
@"%1.f"
,
yValueParsed
];
return
labelText
;
};
self
.
barChart
.
labelMarginTop
=
5
.
0
;
[
self
.
barChart
setXLabels
:@[
@"SEP 1"
,
@"SEP 2"
,
@"SEP 3"
,
@"SEP 4"
,
@"SEP 5"
,
@"SEP 6"
,
@"SEP 7"
]];
self
.
barChart
.
rotateForXAxisText
=
true
;
[
self
.
barChart
setYValues
:@[
@1
,
@24
,
@12
,
@18
,
@30
,
@10
,
@21
]];
[
self
.
barChart
setStrokeColors
:@[
PNGreen
,
PNGreen
,
PNRed
,
PNGreen
,
PNGreen
,
PNYellow
,
PNGreen
]];
// Adding gradient
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"
])
{
//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
)
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"
])
{
//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
:
@"GOOG I/O"
],
];
PNPieChart
*
pieChart
=
[[
PNPieChart
alloc
]
initWithFrame
:
CGRectMake
(
SCREEN_WIDTH
/
2
.
0
-
100
,
135
,
200
.
0
,
200
.
0
)
items
:
items
];
pieChart
.
descriptionTextColor
=
[
UIColor
whiteColor
];
pieChart
.
descriptionTextFont
=
[
UIFont
fontWithName
:
@"Avenir-Medium"
size
:
11
.
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
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
{
NSLog
(
@"Click on line %f, %f, line index is %d"
,
point
.
x
,
point
.
y
,
(
int
)
lineIndex
);
}
-
(
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
;
animation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
animation
.
toValue
=
@1.1
;
animation
.
duration
=
0
.
2
;
animation
.
repeatCount
=
0
;
animation
.
autoreverses
=
YES
;
animation
.
removedOnCompletion
=
YES
;
animation
.
fillMode
=
kCAFillModeForwards
;
[
bar
.
layer
addAnimation
:
animation
forKey
:
@"Float"
];
}
@end
...
...
Please
register
or
login
to post a comment