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-02-26 03:18:51 +0800
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
ca76823eb757d7a968c02500b7432a1f6effdbf0
ca76823e
2 parents
5637e2fa
655d50cc
Merge branch 'master' of github.com:kevinzhow/PNChart
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
20 deletions
PNChart/PNBarChart.m
PNChart/PNBarChart.m
View file @
ca76823
...
...
@@ -11,7 +11,11 @@
#import "PNChartLabel.h"
#import "PNBar.h"
@interface
PNBarChart
()
@interface
PNBarChart
()
{
NSMutableArray
*
_bars
;
NSMutableArray
*
_labels
;
}
-
(
UIColor
*
)
barColorAtIndex
:
(
NSUInteger
)
index
;
@end
...
...
@@ -26,8 +30,10 @@
self
.
clipsToBounds
=
YES
;
_showLabel
=
YES
;
_barBackgroundColor
=
PNLightGrey
;
_labels
=
[
NSMutableArray
array
];
_bars
=
[
NSMutableArray
array
];
}
return
self
;
}
...
...
@@ -35,7 +41,7 @@
{
_yValues
=
yValues
;
[
self
setYLabels
:
yValues
];
_xLabelWidth
=
(
self
.
frame
.
size
.
width
-
chartMargin
*
2
)
/
[
_yValues
count
];
}
...
...
@@ -47,36 +53,38 @@
if
(
value
>
max
)
{
max
=
value
;
}
}
//Min value for Y label
if
(
max
<
5
)
{
max
=
5
;
}
_yValueMax
=
(
int
)
max
;
}
-
(
void
)
setXLabels
:(
NSArray
*
)
xLabels
{
[
self
viewCleanupForCollection
:
_labels
];
_xLabels
=
xLabels
;
if
(
_showLabel
)
{
_xLabelWidth
=
(
self
.
frame
.
size
.
width
-
chartMargin
*
2
)
/
[
xLabels
count
];
for
(
int
index
=
0
;
index
<
xLabels
.
count
;
index
++
)
{
NSString
*
labelText
=
xLabels
[
index
];
PNChartLabel
*
label
=
[[
PNChartLabel
alloc
]
initWithFrame
:
CGRectMake
((
index
*
_xLabelWidth
+
chartMargin
),
self
.
frame
.
size
.
height
-
30
.
0
,
_xLabelWidth
,
20
.
0
)];
[
label
setTextAlignment
:
NSTextAlignmentCenter
];
label
.
text
=
labelText
;
[
_labels
addObject
:
label
];
[
self
addSubview
:
label
];
}
}
}
-
(
void
)
setStrokeColor
:(
UIColor
*
)
strokeColor
...
...
@@ -86,13 +94,13 @@
-
(
void
)
strokeChart
{
[
self
viewCleanupForCollection
:
_bars
];
CGFloat
chartCavanHeight
=
self
.
frame
.
size
.
height
-
chartMargin
*
2
-
40
.
0
;
NSInteger
index
=
0
;
for
(
NSString
*
valueString
in
_yValues
)
{
float
value
=
[
valueString
floatValue
];
float
grade
=
(
float
)
value
/
(
float
)
_yValueMax
;
PNBar
*
bar
;
if
(
_showLabel
)
{
...
...
@@ -100,15 +108,24 @@
}
else
{
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
=
[
self
barColorAtIndex
:
index
];
bar
.
grade
=
grade
;
[
self
addSubview
:
bar
];
bar
.
backgroundColor
=
_barBackgroundColor
;
bar
.
barColor
=
[
self
barColorAtIndex
:
index
];
bar
.
grade
=
grade
;
[
_bars
addObject
:
bar
];
[
self
addSubview
:
bar
];
index
+=
1
;
}
}
-
(
void
)
viewCleanupForCollection
:
(
NSMutableArray
*
)
array
{
if
(
array
.
count
)
{
[
array
makeObjectsPerformSelector
:
@selector
(
removeFromSuperview
)];
[
array
removeAllObjects
];
}
}
#pragma mark - Class extension methods
-
(
UIColor
*
)
barColorAtIndex
:
(
NSUInteger
)
index
...
...
@@ -120,4 +137,4 @@
}
}
@end
@end
\ No newline at end of file
...
...
Please
register
or
login
to post a comment