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
Kevin
2013-12-22 08:15:28 -0800
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
6c1d9ea0eca627a20724c965c2cf14b604d48a6c
6c1d9ea0
2 parents
c8f8f894
8db7a7a8
Merge pull request #22 from schneiderandre/master
Added support to define a color per bar.
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
1 deletions
PNChartDemo/PCChartsTableViewController.m
PNChartDemo/PNChart/PNBarChart.h
PNChartDemo/PNChart/PNBarChart.m
PNChartDemo/PCChartsTableViewController.m
View file @
6c1d9ea
...
...
@@ -108,6 +108,7 @@
barChart
.
backgroundColor
=
[
UIColor
clearColor
];
[
barChart
setXLabels
:@[
@"SEP 1"
,
@"SEP 2"
,
@"SEP 3"
,
@"SEP 4"
,
@"SEP 5"
,
@"SEP 6"
,
@"SEP 7"
]];
[
barChart
setYValues
:@[
@1
,
@24
,
@12
,
@18
,
@30
,
@10
,
@21
]];
[
barChart
setStrokeColors
:@[
PNGreen
,
PNGreen
,
PNRed
,
PNGreen
,
PNGreen
,
PNYellow
,
PNGreen
]];
[
barChart
strokeChart
];
[
viewController
.
view
addSubview
:
barChartLabel
];
...
...
PNChartDemo/PNChart/PNBarChart.h
View file @
6c1d9ea
...
...
@@ -33,6 +33,8 @@
@property
(
nonatomic
,
strong
)
UIColor
*
strokeColor
;
@property
(
nonatomic
,
strong
)
NSArray
*
strokeColors
;
@property
(
nonatomic
,
strong
)
UIColor
*
barBackgroundColor
;
@property
(
nonatomic
)
BOOL
showLabel
;
...
...
PNChartDemo/PNChart/PNBarChart.m
View file @
6c1d9ea
...
...
@@ -11,6 +11,10 @@
#import "PNChartLabel.h"
#import "PNBar.h"
@interface
PNBarChart
()
-
(
UIColor
*
)
barColorAtIndex
:
(
NSUInteger
)
index
;
@end
@implementation
PNBarChart
-
(
id
)
initWithFrame
:(
CGRect
)
frame
...
...
@@ -97,7 +101,7 @@
bar
=
[[
PNBar
alloc
]
initWithFrame
:
CGRectMake
((
index
*
_xLabelWidth
+
chartMargin
+
_xLabelWidth
*
0
.
25
),
self
.
frame
.
size
.
height
-
chartCavanHeight
,
_xLabelWidth
*
0
.
6
,
chartCavanHeight
)];
}
bar
.
backgroundColor
=
_barBackgroundColor
;
bar
.
barColor
=
_strokeColor
;
bar
.
barColor
=
[
self
barColorAtIndex
:
index
]
;
bar
.
grade
=
grade
;
[
self
addSubview
:
bar
];
...
...
@@ -105,4 +109,15 @@
}
}
#pragma mark - Class extension methods
-
(
UIColor
*
)
barColorAtIndex
:
(
NSUInteger
)
index
{
if
([
self
.
strokeColors
count
]
==
[
self
.
yValues
count
])
{
return
self
.
strokeColors
[
index
];
}
else
{
return
self
.
strokeColor
;
}
}
@end
...
...
Please
register
or
login
to post a comment