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
mobileflowllc
2014-08-02 21:02:11 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f78fb5cfb2a955a657f115feac34621b8a1135c5
f78fb5cf
1 parent
bdc11d5a
Add gradient color fill to bar chart
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
68 additions
and
3 deletions
PNChart.podspec
PNChart/PNBarChart/PNBar.h
PNChart/PNBarChart/PNBar.m
PNChart/PNBarChart/PNBarChart.h
PNChart/PNBarChart/PNBarChart.m
PNChartDemo/PCChartsTableViewController.m
Podfile.lock
PNChart.podspec
View file @
f78fb5c
...
...
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
s
.
author
=
{
"Kevin"
=>
"kevinchou.c@gmail.com"
}
s
.
platform
=
:ios
,
'6.0'
s
.
source
=
{
:git
=>
"https://github.com/
kevinzhow
/PNChart.git"
}
s
.
source
=
{
:git
=>
"https://github.com/
moflo
/PNChart.git"
}
s
.
ios
.
dependency
'UICountingLabel'
,
'~> 1.0.0'
...
...
PNChart/PNBarChart/PNBar.h
View file @
f78fb5c
...
...
@@ -16,6 +16,7 @@
@property
(
nonatomic
)
float
grade
;
@property
(
nonatomic
)
CAShapeLayer
*
chartLine
;
@property
(
nonatomic
)
UIColor
*
barColor
;
@property
(
nonatomic
)
UIColor
*
barColorGradientStart
;
@property
(
nonatomic
)
CGFloat
barRadius
;
@end
...
...
PNChart/PNBarChart/PNBar.m
View file @
f78fb5c
...
...
@@ -64,6 +64,43 @@
[
_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
);
CGMutablePathRef
t
=
CGPathCreateMutable
();
CGPathMoveToPoint
(
t
,
NULL
,
0
,
0
);
CGPathAddLineToPoint
(
t
,
NULL
,
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"
];
}
}
...
...
@@ -74,6 +111,17 @@
}
completion
:
nil
];
}
-
(
void
)
setBarColorGradientStart
:
(
UIColor
*
)
barColorGradientStart
{
// Set gradient color, remove any existing sublayer first
for
(
CALayer
*
sublayer
in
[
_chartLine
sublayers
])
{
[
sublayer
removeFromSuperlayer
];
}
_barColorGradientStart
=
barColorGradientStart
;
[
self
setGrade
:
_grade
];
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
...
...
PNChart/PNBarChart/PNBarChart.h
View file @
f78fb5c
...
...
@@ -123,6 +123,12 @@ typedef NSString *(^PNyLabelFromatter)(CGFloat yLabelValue);
*/
@property
(
nonatomic
)
CGFloat
yMinValue
;
/*
switch to indicate that the bar should be filled as a gradient
*/
@property
(
nonatomic
)
UIColor
*
barColorGradientStart
;
@property
(
nonatomic
,
retain
)
id
<
PNChartDelegate
>
delegate
;
@end
...
...
PNChart/PNBarChart/PNBarChart.m
View file @
f78fb5c
...
...
@@ -205,9 +205,14 @@
//Height Of Bar
bar
.
grade
=
grade
;
// Add gradient
bar
.
barColorGradientStart
=
_barColorGradientStart
;
//For Click Index
bar
.
tag
=
index
;
[
_bars
addObject
:
bar
];
[
self
addSubview
:
bar
];
...
...
PNChartDemo/PCChartsTableViewController.m
View file @
f78fb5c
...
...
@@ -119,8 +119,13 @@
[
self
.
barChart
setXLabels
:@[
@"SEP 1"
,
@"SEP 2"
,
@"SEP 3"
,
@"SEP 4"
,
@"SEP 5"
,
@"SEP 6"
,
@"SEP 7"
]];
[
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
];
...
...
@@ -152,7 +157,7 @@
}
else
if
([
segue
.
identifier
isEqualToString
:
@"pieChart"
])
{
//Add
Lin
eChart
//Add
Pi
eChart
UILabel
*
pieChartLabel
=
[[
UILabel
alloc
]
initWithFrame
:
CGRectMake
(
0
,
90
,
SCREEN_WIDTH
,
30
)];
pieChartLabel
.
text
=
@"Pie Chart"
;
pieChartLabel
.
textColor
=
PNFreshGreen
;
...
...
Podfile.lock
View file @
f78fb5c
...
...
@@ -5,6 +5,6 @@ DEPENDENCIES:
- UICountingLabel (~> 1.0.0)
SPEC CHECKSUMS:
UICountingLabel:
bb976960c0130785a600aac592954c23eb395096
UICountingLabel:
0a0e9e34bf4690dbd127aaec552d19ed938087a9
COCOAPODS: 0.32.1
...
...
Please
register
or
login
to post a comment