+0
Daily
9,627
stars
1,732
forks
320
watchers
146
prs
317
issues
2
releases
README
PNChart
You can also find swift version at here https://github.com/kevinzhow/PNChart-Swift
A simple and beautiful chart lib with animation used in Piner and CoinsMan for iOS
Requirements
PNChart works on iOS 7.0+ and is compatible with ARC projects.
If you need support for iOS 6, use PNChart <= 0.8.1. Note that 0.8.2 supports iOS 8.0+ only, 0.8.3 and newer supports iOS 7.0+.
It depends on the following Apple frameworks, which should already be included with most Xcode templates:
Foundation.framework
UIKit.framework
CoreGraphics.framework
QuartzCore.framework
You will need LLVM 3.0 or later in order to build PNChart.
Usage
Cocoapods
CocoaPods is the recommended way to add PNChart to your project.
1. Add a pod entry for PNChart to your Podfile pod 'PNChart'
2. Install the pod(s) by running pod install.
3. Include PNChart wherever you need it with import "PNChart.h".
Copy the PNChart folder to your project
objective-c
import "PNChart.h"
//For Line Chart
PNLineChart lineChart = [[PNLineChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)];
[lineChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5"]];
// Line Chart No.1
NSArray data01Array = @[@60.1, @160.1, @126.4, @262.2, @186.2];
PNLineChartData data01 = [PNLineChartData new];
data01.color = PNFreshGreen;
data01.itemCount = lineChart.xLabels.count;
data01.getData = ^(NSUInteger index) {
CGFloat yValue = [data01Array[index] floatValue];
return [PNLineChartDataItem dataItemWithY:yValue];
};
// Line Chart No.2
NSArray data02Array = @[@20.1, @180.1, @26.4, @202.2, @126.2];
PNLineChartData data02 = [PNLineChartData new];
data02.color = PNTwitterColor;
data02.itemCount = lineChart.xLabels.count;
data02.getData = ^(NSUInteger index) {
CGFloat yValue = [data02Array[index] floatValue];
return [PNLineChartDataItem dataItemWithY:yValue];
};
lineChart.chartData = @[data01, data02];
[lineChart strokeChart];
You can choose to show smooth lines.
objective-c
lineChart.showSmoothLines = YES;
You can set different colors for the same PNLineChartData item. for instance you can use "color" red for values less than 50 and use purple for values greater than 150.
objective-c
lineChartData.rangeColors = @[
[[PNLineChartColorRange alloc] initWithRange:NSMakeRange(10, 30) color:[UIColor redColor]],
[[PNLineChartColorRange alloc] initWithRange:NSMakeRange(100, 200) color:[UIColor purpleColor]]
];
objective-c
import "PNChart.h"
//For BarC hart
PNBarChart barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)];
[barChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5"]];
[barChart setYValues:@[@1, @10, @2, @6, @3]];
[barChart strokeChart];
objective-c
import "PNChart.h"
//For Circle Chart
PNCircleChart circleChart = [[PNCircleChart alloc] initWithFrame:CGRectMake(0, 80.0, SCREEN_WIDTH, 100.0) total:[NSNumber numberWithInt:100] current:[NSNumber numberWithInt:60] clockwiseTop issues
#72size of chart12 comments · 2014-07-08#157PNBarChart Can't work: yValues Error!10 comments · 2015-02-05#254PNLineChart 的横坐标超出屏幕范围 不能移动吗?8 comments · 2015-10-28#437怎么去除PNChart中为0的点7 comments · 2018-05-07#46Static x values if y values at index are null?6 comments · 2014-04-01#399Line Chart X 轴坐标文字对不齐5 comments · 2017-08-29#316柱状图怎么显示多个4 comments · 2016-07-22#222Chart width in UITableViewCell5 comments · 2015-07-01
Latest release
0.5 0.5 2014-05-05Now we have a simple & beautiful Pie Chart thx to @ZhangHang