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-06-01 15:59:49 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
68528f59bf6629d8d99f0955e819d88aa65aee00
68528f59
1 parent
98869cd5
Optimize Precision
Optimize Negative show
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
44 deletions
PNChart/PNBar.m
PNChart/PNBarChart.h
PNChart/PNBarChart.m
PNChartDemo/PCChartViewController.m
PNChart/PNBar.m
View file @
68528f5
...
...
@@ -45,7 +45,6 @@
-
(
void
)
setGrade
:(
float
)
grade
{
NSLog
(
@"New garde %f"
,
grade
);
_copyGrade
=
grade
;
CGFloat
startPosY
=
(
1
-
grade
)
*
self
.
frame
.
size
.
height
;
...
...
@@ -228,7 +227,7 @@
}
-
(
void
)
setIsNegative
:
(
BOOL
)
isNegative
{
if
(
isNegative
)
{
[
self
.
textLayer
setString
:[[
NSString
alloc
]
initWithFormat
:
@"-
%0
.f"
,
_grade
*
self
.
maxDivisor
]];
[
self
.
textLayer
setString
:[[
NSString
alloc
]
initWithFormat
:
@"-
%1
.f"
,
_grade
*
self
.
maxDivisor
]];
CGSize
size
=
CGSizeMake
(
320
,
2000
);
//设置一个行高上限
NSDictionary
*
attributes
=
@{
NSFontAttributeName
:
[
UIFont
systemFontOfSize
:
18
.
0
]};
...
...
PNChart/PNBarChart.h
View file @
68528f5
...
...
@@ -32,7 +32,7 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue);
@property
(
nonatomic
)
NSMutableArray
*
bars
;
@property
(
nonatomic
)
CGFloat
xLabelWidth
;
@property
(
nonatomic
)
in
t
yValueMax
;
@property
(
nonatomic
)
floa
t
yValueMax
;
@property
(
nonatomic
)
UIColor
*
strokeColor
;
@property
(
nonatomic
)
NSArray
*
strokeColors
;
...
...
PNChart/PNBarChart.m
View file @
68528f5
...
...
@@ -117,8 +117,6 @@
}
}
-
(
void
)
updateChartData
:
(
NSArray
*
)
data
{
self
.
yValues
=
data
;
[
self
updateBar
];
...
...
@@ -126,10 +124,10 @@
-
(
void
)
getYValueMax
:
(
NSArray
*
)
yLabels
{
int
max
=
[[
yLabels
valueForKeyPath
:
@"@max.intValue"
]
in
tValue
];
CGFloat
max
=
[[
yLabels
valueForKeyPath
:
@"@max.floatValue"
]
floa
tValue
];
//ensure max is even
_yValueMax
=
max
%
2
==
0
?
max
:
max
+
1
;
_yValueMax
=
max
;
if
(
_yValueMax
==
0
)
{
_yValueMax
=
_yMinValue
;
...
...
@@ -227,7 +225,6 @@
//Change Bar Background color
bar
.
backgroundColor
=
_barBackgroundColor
;
//Bar StrokColor First
if
(
self
.
strokeColor
)
{
bar
.
barColor
=
self
.
strokeColor
;
...
...
@@ -249,27 +246,26 @@
//Height Of Bar
float
value
=
[
valueString
floatValue
];
float
grade
=
ABS
((
float
)
value
/
(
float
)
_yValueMax
);
float
grade
=
fabsf
((
float
)
value
/
(
float
)
_yValueMax
);
if
(
isnan
(
grade
))
{
grade
=
0
;
}
bar
.
maxDivisor
=
(
float
)
_yValueMax
;
bar
.
grade
=
grade
;
bar
.
isShowNumber
=
self
.
isShowNumbers
;
bar
.
isShowNumber
=
self
.
isShowNumbers
;
CGRect
originalFrame
=
bar
.
frame
;
if
(
value
<
0
&&
self
.
showLevelLine
)
{
CGAffineTransform
transform
=
CGAffineTransformMakeRotation
(
M_PI
);
[
bar
setTransform
:
transform
];
originalFrame
.
origin
.
y
=
bar
.
frame
.
origin
.
y
+
bar
.
frame
.
size
.
height
;
bar
.
frame
=
originalFrame
;
bar
.
isNegative
=
YES
;
}
index
+=
1
;
NSString
*
currentNumber
=
[
NSString
stringWithFormat
:
@"%f"
,
value
];
if
([[
currentNumber
substringToIndex
:
1
]
isEqualToString
:
@"-"
]
&&
self
.
showLevelLine
)
{
CGAffineTransform
transform
=
CGAffineTransformMakeRotation
(
M_PI
);
[
bar
setTransform
:
transform
]
;
originalFrame
.
origin
.
y
=
bar
.
frame
.
origin
.
y
+
bar
.
frame
.
size
.
height
;
bar
.
frame
=
originalFrame
;
bar
.
isNegative
=
YES
;
}
index
+=
1
;
}
}
...
...
@@ -301,11 +297,8 @@
[
progressline
setLineWidth
:
1
.
0
];
[
progressline
setLineCapStyle
:
kCGLineCapSquare
];
_chartBottomLine
.
path
=
progressline
.
CGPath
;
_chartBottomLine
.
strokeColor
=
PNLightGrey
.
CGColor
;
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
pathAnimation
.
duration
=
0
.
5
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
...
...
@@ -333,11 +326,8 @@
[
progressLeftline
setLineWidth
:
1
.
0
];
[
progressLeftline
setLineCapStyle
:
kCGLineCapSquare
];
_chartLeftLine
.
path
=
progressLeftline
.
CGPath
;
_chartLeftLine
.
strokeColor
=
PNLightGrey
.
CGColor
;
CABasicAnimation
*
pathLeftAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
pathLeftAnimation
.
duration
=
0
.
5
;
pathLeftAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
...
...
@@ -367,10 +357,8 @@
[
progressline
setLineCapStyle
:
kCGLineCapSquare
];
_chartLevelLine
.
path
=
progressline
.
CGPath
;
_chartLevelLine
.
strokeColor
=
PNLightGrey
.
CGColor
;
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
pathAnimation
.
duration
=
0
.
5
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
...
...
@@ -381,10 +369,14 @@
_chartLevelLine
.
strokeEnd
=
1
.
0
;
[
self
.
layer
addSublayer
:
_chartLevelLine
];
}
else
{
if
(
_chartLevelLine
)
{
[
_chartLevelLine
removeFromSuperlayer
];
_chartLevelLine
=
nil
;
}
}
}
-
(
void
)
viewCleanupForCollection
:
(
NSMutableArray
*
)
array
{
if
(
array
.
count
)
{
...
...
@@ -406,7 +398,6 @@
}
}
#pragma mark - Touch detection
-
(
void
)
touchesBegan
:
(
NSSet
*
)
touches
withEvent
:
(
UIEvent
*
)
event
...
...
@@ -415,7 +406,6 @@
[
super
touchesBegan
:
touches
withEvent
:
event
];
}
-
(
void
)
touchPoint
:
(
NSSet
*
)
touches
withEvent
:
(
UIEvent
*
)
event
{
//Get the point user touched
...
...
PNChartDemo/PCChartViewController.m
View file @
68528f5
...
...
@@ -97,23 +97,17 @@
self
.
barChart
.
backgroundColor
=
[
UIColor
clearColor
];
self
.
barChart
.
yLabelFormatter
=
^
(
CGFloat
yValue
){
CGFloat
yValueParsed
=
yValue
;
NSString
*
labelText
=
[
NSString
stringWithFormat
:
@"%
1
.f"
,
yValueParsed
];
NSString
*
labelText
=
[
NSString
stringWithFormat
:
@"%
0
.f"
,
yValueParsed
];
return
labelText
;
};
self
.
barChart
.
labelMarginTop
=
5
.
0
;
self
.
barChart
.
showLevelLine
=
YES
;
self
.
barChart
.
showChartBorder
=
YES
;
[
self
.
barChart
setXLabels
:@[
@"2"
,
@"3"
,
@"4"
,
@"5"
]];
self
.
barChart
.
rotateForXAxisText
=
true
;
self
.
barChart
.
yLabelSum
=
5
;
self
.
barChart
.
yValueMax
=
10
;
self
.
barChart
.
yLabels
=
@[
@
-
10
,
@0
,
@10
];
[
self
.
barChart
setYValues
:@[
@1
,
@5
,
@
(
0
-
8
),
@10
]];
// self.barChart.yLabels = @[@-10,@0,@10];
[
self
.
barChart
setYValues
:@[
@10.82
,
@1.88
,
@6.96
,
@33.93
]];
[
self
.
barChart
setStrokeColors
:@[
PNGreen
,
PNGreen
,
PNRed
,
PNGreen
]];
self
.
barChart
.
isGradientShow
=
NO
;
self
.
barChart
.
isShowNumbers
=
NO
;
// self.barChart.isGradientShow = NO;
self
.
barChart
.
isShowNumbers
=
YES
;
[
self
.
barChart
strokeChart
];
self
.
barChart
.
delegate
=
self
;
...
...
Please
register
or
login
to post a comment