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
dullgrass
2015-05-14 16:39:23 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
74652e09cb7f1ff0b1e6270e3e82635ebce836bc
74652e09
1 parent
dbbbd0ae
no message
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
4 deletions
PNChart/PNBarChart.m
PNChart/PNBarChart.m
View file @
74652e0
...
...
@@ -10,6 +10,7 @@
#import "PNColor.h"
#import "PNChartLabel.h"
#define defaultYSum 0 //默认的Y显示值的个数,
@interface
PNBarChart
()
{
NSMutableArray
*
_xChartLabels
;
...
...
@@ -70,8 +71,12 @@
//make the _yLabelSum value dependant of the distinct values of yValues to avoid duplicates on yAxis
int
yLabelsDifTotal
=
(
int
)[
NSSet
setWithArray
:
yValues
].
count
;
_yLabelSum
=
yLabelsDifTotal
%
2
==
0
?
yLabelsDifTotal
:
yLabelsDifTotal
+
1
;
// !!!: 调整Y坐标的显示值
if
(
_yLabelSum
==
defaultYSum
)
{
_yLabelSum
=
yLabelsDifTotal
%
2
==
0
?
yLabelsDifTotal
:
yLabelsDifTotal
+
1
;
}
if
(
_yMaxValue
)
{
_yValueMax
=
_yMaxValue
;
}
else
{
...
...
@@ -86,10 +91,36 @@
if
(
_showLabel
)
{
//Add y labels
float
yLabelSectionHeight
=
(
self
.
frame
.
size
.
height
-
_chartMargin
*
2
-
kXLabelHeight
)
/
_yLabelSum
;
// !!!: 用户自行修改Y轴坐标值
if
(
_yLabels
)
{
float
yLabelSectionHeight
=
(
self
.
frame
.
size
.
height
-
_chartMargin
*
2
-
kXLabelHeight
)
/
_yLabelSum
;
[
self
getYValueMax
:
_yLabels
]
;
for
(
int
index
=
0
;
index
<
_yLabelSum
;
index
++
)
{
for
(
int
i
=
0
;
i
<
_yLabels
.
count
;
i
++
)
{
float
yAsixValues
=
[[
_yLabels
objectAtIndex
:
_yLabels
.
count
-
i
-
1
]
floatValue
];
NSString
*
labelText
=
_yLabelFormatter
(
yAsixValues
);
PNChartLabel
*
label
=
[[
PNChartLabel
alloc
]
initWithFrame
:
CGRectMake
(
0
,
yLabelSectionHeight
*
i
+
_chartMargin
-
kYLabelHeight
/
2
.
0
,
_yChartLabelWidth
,
kYLabelHeight
)];
label
.
font
=
_labelFont
;
label
.
textColor
=
_labelTextColor
;
[
label
setTextAlignment
:
NSTextAlignmentRight
];
label
.
text
=
labelText
;
[
_yChartLabels
addObject
:
label
];
[
self
addSubview
:
label
];
}
}
else
{
for
(
int
index
=
0
;
index
<
_yLabelSum
;
index
++
)
{
NSString
*
labelText
=
_yLabelFormatter
((
float
)
_yValueMax
*
(
(
_yLabelSum
-
index
)
/
(
float
)
_yLabelSum
));
...
...
@@ -106,6 +137,7 @@
[
self
addSubview
:
label
];
}
}
}
}
...
...
Please
register
or
login
to post a comment