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-12-12 04:46:03 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
39dab068ff1d87c4d42859fc94f0159a8f356b6e
39dab068
1 parent
3086fa90
Add change value details
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
43 deletions
PNChartDemo/PCChartViewController.h
PNChartDemo/PCChartViewController.m
PNChartDemo/PCChartsTableViewController.m
PNChartDemo/PCChartViewController.h
View file @
39dab06
...
...
@@ -7,8 +7,12 @@
//
#import <UIKit/UIKit.h>
#import "PNChartDelegate.h"
#import "PNChart.h"
@interface
PCChartViewController
:
UIViewController
@interface
PCChartViewController
:
UIViewController
<
PNChartDelegate
>
@property
(
nonatomic
)
PNLineChart
*
lineChart
;
-
(
IBAction
)
changeValue
:(
id
)
sender
;
@end
...
...
PNChartDemo/PCChartViewController.m
View file @
39dab06
...
...
@@ -10,8 +10,93 @@
@implementation
PCChartViewController
-
(
void
)
viewDidLoad
{
[
super
viewDidLoad
];
if
([
self
.
title
isEqualToString
:
@"Line Chart"
])
{
UILabel
*
lineChartLabel
=
[[
UILabel
alloc
]
initWithFrame
:
CGRectMake
(
0
,
90
,
SCREEN_WIDTH
,
30
)];
lineChartLabel
.
text
=
@"Line Chart"
;
lineChartLabel
.
textColor
=
PNFreshGreen
;
lineChartLabel
.
font
=
[
UIFont
fontWithName
:
@"Avenir-Medium"
size
:
23
.
0
];
lineChartLabel
.
textAlignment
=
NSTextAlignmentCenter
;
self
.
lineChart
=
[[
PNLineChart
alloc
]
initWithFrame
:
CGRectMake
(
0
,
135
.
0
,
SCREEN_WIDTH
,
200
.
0
)];
self
.
lineChart
.
yLabelFormat
=
@"%1.1f"
;
self
.
lineChart
.
backgroundColor
=
[
UIColor
clearColor
];
[
self
.
lineChart
setXLabels
:@[
@"SEP 1"
,
@"SEP 2"
,
@"SEP 3"
,
@"SEP 4"
,
@"SEP 5"
,
@"SEP 6"
,
@"SEP 7"
]];
self
.
lineChart
.
showCoordinateAxis
=
YES
;
// Line Chart #1
NSArray
*
data01Array
=
@[
@60.1
,
@160.1
,
@126.4
,
@262.2
,
@186.2
,
@127.2
,
@176.2
];
PNLineChartData
*
data01
=
[
PNLineChartData
new
];
data01
.
color
=
PNFreshGreen
;
data01
.
itemCount
=
data01Array
.
count
;
data01
.
inflexionPointStyle
=
PNLineChartPointStyleTriangle
;
data01
.
getData
=
^
(
NSUInteger
index
)
{
CGFloat
yValue
=
[
data01Array
[
index
]
floatValue
];
return
[
PNLineChartDataItem
dataItemWithY
:
yValue
];
};
// Line Chart #2
NSArray
*
data02Array
=
@[
@20.1
,
@180.1
,
@26.4
,
@202.2
,
@126.2
,
@167.2
,
@276.2
];
PNLineChartData
*
data02
=
[
PNLineChartData
new
];
data02
.
color
=
PNTwitterColor
;
data02
.
itemCount
=
data02Array
.
count
;
data02
.
inflexionPointStyle
=
PNLineChartPointStyleSquare
;
data02
.
getData
=
^
(
NSUInteger
index
)
{
CGFloat
yValue
=
[
data02Array
[
index
]
floatValue
];
return
[
PNLineChartDataItem
dataItemWithY
:
yValue
];
};
self
.
lineChart
.
chartData
=
@[
data01
,
data02
];
[
self
.
lineChart
strokeChart
];
self
.
lineChart
.
delegate
=
self
;
[
self
.
view
addSubview
:
lineChartLabel
];
[
self
.
view
addSubview
:
self
.
lineChart
];
}
}
-
(
void
)
userClickedOnLineKeyPoint
:
(
CGPoint
)
point
lineIndex
:
(
NSInteger
)
lineIndex
pointIndex
:
(
NSInteger
)
pointIndex
{
NSLog
(
@"Click Key on line %f, %f line index is %d and point index is %d"
,
point
.
x
,
point
.
y
,(
int
)
lineIndex
,
(
int
)
pointIndex
);
}
-
(
void
)
userClickedOnLinePoint
:
(
CGPoint
)
point
lineIndex
:
(
NSInteger
)
lineIndex
{
NSLog
(
@"Click on line %f, %f, line index is %d"
,
point
.
x
,
point
.
y
,
(
int
)
lineIndex
);
}
-
(
IBAction
)
changeValue
:
(
id
)
sender
{
if
([
self
.
title
isEqualToString
:
@"Bar Chart"
])
{
if
([
self
.
title
isEqualToString
:
@"Line Chart"
])
{
// Line Chart #1
NSArray
*
data01Array
=
@[
@30.1
,
@20.1
,
@106.4
,
@162.2
,
@86.2
,
@27.2
,
@76.2
];
PNLineChartData
*
data01
=
[
PNLineChartData
new
];
data01
.
color
=
PNFreshGreen
;
data01
.
itemCount
=
data01Array
.
count
;
data01
.
inflexionPointStyle
=
PNLineChartPointStyleTriangle
;
data01
.
getData
=
^
(
NSUInteger
index
)
{
CGFloat
yValue
=
[
data01Array
[
index
]
floatValue
];
return
[
PNLineChartDataItem
dataItemWithY
:
yValue
];
};
// Line Chart #2
NSArray
*
data02Array
=
@[
@60.1
,
@120.1
,
@126.4
,
@102.2
,
@26.2
,
@67.2
,
@176.2
];
PNLineChartData
*
data02
=
[
PNLineChartData
new
];
data02
.
color
=
PNTwitterColor
;
data02
.
itemCount
=
data02Array
.
count
;
data02
.
inflexionPointStyle
=
PNLineChartPointStyleSquare
;
data02
.
getData
=
^
(
NSUInteger
index
)
{
CGFloat
yValue
=
[
data02Array
[
index
]
floatValue
];
return
[
PNLineChartDataItem
dataItemWithY
:
yValue
];
};
[
self
.
lineChart
updateChartData
:@[
data01
,
data02
]];
}
}
...
...
PNChartDemo/PCChartsTableViewController.m
View file @
39dab06
...
...
@@ -21,47 +21,6 @@
if
([
segue
.
identifier
isEqualToString
:
@"lineChart"
])
{
//Add line chart
UILabel
*
lineChartLabel
=
[[
UILabel
alloc
]
initWithFrame
:
CGRectMake
(
0
,
90
,
SCREEN_WIDTH
,
30
)];
lineChartLabel
.
text
=
@"Line Chart"
;
lineChartLabel
.
textColor
=
PNFreshGreen
;
lineChartLabel
.
font
=
[
UIFont
fontWithName
:
@"Avenir-Medium"
size
:
23
.
0
];
lineChartLabel
.
textAlignment
=
NSTextAlignmentCenter
;
PNLineChart
*
lineChart
=
[[
PNLineChart
alloc
]
initWithFrame
:
CGRectMake
(
0
,
135
.
0
,
SCREEN_WIDTH
,
200
.
0
)];
lineChart
.
yLabelFormat
=
@"%1.1f"
;
lineChart
.
backgroundColor
=
[
UIColor
clearColor
];
[
lineChart
setXLabels
:@[
@"SEP 1"
,
@"SEP 2"
,
@"SEP 3"
,
@"SEP 4"
,
@"SEP 5"
,
@"SEP 6"
,
@"SEP 7"
]];
lineChart
.
showCoordinateAxis
=
YES
;
// Line Chart #1
NSArray
*
data01Array
=
@[
@60.1
,
@160.1
,
@126.4
,
@262.2
,
@186.2
,
@127.2
,
@176.2
];
PNLineChartData
*
data01
=
[
PNLineChartData
new
];
data01
.
color
=
PNFreshGreen
;
data01
.
itemCount
=
lineChart
.
xLabels
.
count
;
data01
.
inflexionPointStyle
=
PNLineChartPointStyleTriangle
;
data01
.
getData
=
^
(
NSUInteger
index
)
{
CGFloat
yValue
=
[
data01Array
[
index
]
floatValue
];
return
[
PNLineChartDataItem
dataItemWithY
:
yValue
];
};
// Line Chart #2
NSArray
*
data02Array
=
@[
@20.1
,
@180.1
,
@26.4
,
@202.2
,
@126.2
,
@167.2
,
@276.2
];
PNLineChartData
*
data02
=
[
PNLineChartData
new
];
data02
.
color
=
PNTwitterColor
;
data02
.
itemCount
=
lineChart
.
xLabels
.
count
;
data02
.
inflexionPointStyle
=
PNLineChartPointStyleSquare
;
data02
.
getData
=
^
(
NSUInteger
index
)
{
CGFloat
yValue
=
[
data02Array
[
index
]
floatValue
];
return
[
PNLineChartDataItem
dataItemWithY
:
yValue
];
};
lineChart
.
chartData
=
@[
data01
,
data02
];
[
lineChart
strokeChart
];
lineChart
.
delegate
=
self
;
[
viewController
.
view
addSubview
:
lineChartLabel
];
[
viewController
.
view
addSubview
:
lineChart
];
viewController
.
title
=
@"Line Chart"
;
...
...
Please
register
or
login
to post a comment