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
2015-03-12 15:42:57 +0800
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
fb07904344edb0e6e64d1dd41d11fa0d69489e4e
fb079043
2 parents
fa451958
71efc1d3
Merge pull request #174 from lunzii/master
Add PNLineChart with setYLabels.
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
7 deletions
PNChart/PNLineChart.h
PNChart/PNLineChart.m
PNChartDemo/PCChartViewController.m
PNChart/PNLineChart.h
View file @
fb07904
...
...
@@ -47,6 +47,8 @@
@property
(
nonatomic
)
CGFloat
chartCavanWidth
;
@property
(
nonatomic
)
CGFloat
chartMargin
;
@property
(
nonatomic
)
BOOL
showLabel
;
@property
(
nonatomic
)
BOOL
showGenYLabels
;
/**
* Controls whether to show the coordinate axis. Default is NO.
...
...
PNChart/PNLineChart.m
View file @
fb07904
...
...
@@ -52,7 +52,7 @@
#pragma mark instance methods
-
(
void
)
setYLabels
:(
NSArray
*
)
yLabels
-
(
void
)
setYLabels
{
CGFloat
yStep
=
(
_yValueMax
-
_yValueMin
)
/
_yLabelNum
;
CGFloat
yStepHeight
=
_chartCavanHeight
/
_yLabelNum
;
...
...
@@ -104,6 +104,54 @@
}
}
-
(
void
)
setYLabels
:
(
NSArray
*
)
yLabels
{
_showGenYLabels
=
NO
;
_yLabelNum
=
yLabels
.
count
-
1
;
CGFloat
yLabelHeight
;
if
(
_showLabel
)
{
yLabelHeight
=
_chartCavanHeight
/
[
yLabels
count
];
}
else
{
yLabelHeight
=
(
self
.
frame
.
size
.
height
)
/
[
yLabels
count
];
}
return
[
self
setYLabels
:
yLabels
withHeight
:
yLabelHeight
];
}
-
(
void
)
setYLabels
:
(
NSArray
*
)
yLabels
withHeight
:
(
CGFloat
)
height
{
_yLabels
=
yLabels
;
_yLabelHeight
=
height
;
if
(
_yChartLabels
)
{
for
(
PNChartLabel
*
label
in
_yChartLabels
)
{
[
label
removeFromSuperview
];
}
}
else
{
_yChartLabels
=
[
NSMutableArray
new
];
}
NSString
*
labelText
;
if
(
_showLabel
)
{
CGFloat
yStepHeight
=
_chartCavanHeight
/
_yLabelNum
;
for
(
int
index
=
0
;
index
<
yLabels
.
count
;
index
++
)
{
labelText
=
yLabels
[
index
];
#warning modify origin
NSInteger
y
=
(
NSInteger
)(
_chartCavanHeight
-
index
*
yStepHeight
);
PNChartLabel
*
label
=
[[
PNChartLabel
alloc
]
initWithFrame
:
CGRectMake
(
0
.
0
,
y
,
(
NSInteger
)
_chartMargin
,
(
NSInteger
)
_yLabelHeight
)];
[
label
setTextAlignment
:
NSTextAlignmentRight
];
label
.
text
=
labelText
;
[
self
setCustomStyleForYLabel
:
label
];
[
self
addSubview
:
label
];
[
_yChartLabels
addObject
:
label
];
}
}
}
-
(
CGFloat
)
computeEqualWidthForXLabels
:
(
NSArray
*
)
xLabels
{
CGFloat
xLabelWidth
;
...
...
@@ -548,8 +596,8 @@
_yValueMin
=
_yFixedValueMin
?
_yFixedValueMin
:
yMin
;
_yValueMax
=
_yFixedValueMax
?
_yFixedValueMax
:
yMax
+
yMax
/
10
.
0
;
if
(
_show
Label
)
{
[
self
setYLabels
:
yLabelsArray
];
if
(
_show
GenYLabels
)
{
[
self
setYLabels
];
}
}
...
...
@@ -683,6 +731,7 @@
self
.
clipsToBounds
=
YES
;
self
.
chartLineArray
=
[
NSMutableArray
new
];
_showLabel
=
YES
;
_showGenYLabels
=
YES
;
_pathPoints
=
[[
NSMutableArray
alloc
]
init
];
_endPointsOfPath
=
[[
NSMutableArray
alloc
]
init
];
self
.
userInteractionEnabled
=
YES
;
...
...
PNChartDemo/PCChartViewController.m
View file @
fb07904
...
...
@@ -33,11 +33,22 @@
//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
;
self
.
lineChart
.
yFixedValueMax
=
300
.
0
;
self
.
lineChart
.
yFixedValueMin
=
0
.
0
;
[
self
.
lineChart
setYLabels
:@[
@"0 min"
,
@"50 min"
,
@"100 min"
,
@"150 min"
,
@"200 min"
,
@"250 min"
,
@"300 min"
,
]
];
// Line Chart #1
NSArray
*
data01Array
=
@[
@60.1
,
@160.1
,
@126.4
,
@
262.2
,
@186.2
,
@127.2
,
@176.2
];
NSArray
*
data01Array
=
@[
@60.1
,
@160.1
,
@126.4
,
@
0.0
,
@186.2
,
@127.2
,
@176.2
];
PNLineChartData
*
data01
=
[
PNLineChartData
new
];
data01
.
dataTitle
=
@"Alpha"
;
data01
.
color
=
PNFreshGreen
;
...
...
@@ -50,7 +61,7 @@
};
// Line Chart #2
NSArray
*
data02Array
=
@[
@
20.1
,
@180.1
,
@26.4
,
@202.2
,
@126.2
,
@167.2
,
@276.2
];
NSArray
*
data02Array
=
@[
@
0.0
,
@180.1
,
@26.4
,
@202.2
,
@126.2
,
@167.2
,
@276.2
];
PNLineChartData
*
data02
=
[
PNLineChartData
new
];
data02
.
dataTitle
=
@"Beta Beta Beta Beta"
;
data02
.
color
=
PNTwitterColor
;
...
...
Please
register
or
login
to post a comment