PNChart

简介:

PNChart

https://github.com/kevinzhow/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

你也可以在这里 https://github.com/kevinzhow/PNChart-Swift 找到 swift 版本。

一个简单而精美的表格动画库,你可以在  Piner 与 CoinsMan 应用中看到它的用处。

 

Requirements

PNChart works on iOS 6.0 (Begin with 0.8.2 supports iOS 8 and Later only, if you are working with iOS 6 and iOS 7, use 0.8.1 instead.) and later version and is compatible with ARC projects. It depends on the following Apple frameworks, which should already be included with most Xcode templates:

PNChart 运行在 iOS 6.0 以及以上。后续版本兼容 ARC ,它依赖于以下几个框架:

  • Foundation.framework
  • UIKit.framework
  • CoreGraphics.framework
  • QuartzCore.framework

You will need LLVM 3.0 or later in order to build PNChart.

你需要 LLVM 3.0 以及其以上版本才能够编译PNChart。

 

Usage

Cocoapods

CocoaPods is the recommended way to add PNChart to your project.

我们推荐你 CocoaPods 来将PNChart添加到你的项目当中。

  1. Add a pod entry for PNChart to your Podfile pod 'PNChart' 将'PNChart'添加到你的pod文件中
  2. Install the pod(s) by running pod install. 你需要通过 pod install 命令来安装
  3. Include PNChart wherever you need it with #import "PNChart.h". 然后,在任何你需要使用的地方,引入头文件“PNChart.h”即可

Copy the PNChart folder to your project

#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];

#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];

#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] clockwise:NO shadow:NO]; circleChart.backgroundColor = [UIColor clearColor]; [circleChart setStrokeColor:PNGreen]; [circleChart strokeChart];

# import "PNChart.h"
//For Pie Chart
NSArray *items = @[[PNPieChartDataItem dataItemWithValue:10 color:PNRed], [PNPieChartDataItem dataItemWithValue:20 color:PNBlue description:@"WWDC"], [PNPieChartDataItem dataItemWithValue:40 color:PNGreen description:@"GOOL I/O"], ]; PNPieChart *pieChart = [[PNPieChart alloc] initWithFrame:CGRectMake(40.0, 155.0, 240.0, 240.0) items:items]; pieChart.descriptionTextColor = [UIColor whiteColor]; pieChart.descriptionTextFont = [UIFont fontWithName:@"Avenir-Medium" size:14.0]; [pieChart strokeChart];

# import "PNChart.h"
//For Scatter Chart

PNScatterChart *scatterChart = [[PNScatterChart alloc] initWithFrame:CGRectMake(SCREEN_WIDTH /6.0 - 30, 135, 280, 200)]; [scatterChart setAxisXWithMinimumValue:20 andMaxValue:100 toTicks:6]; [scatterChart setAxisYWithMinimumValue:30 andMaxValue:50 toTicks:5]; NSArray * data01Array = [self randomSetOfObjects]; PNScatterChartData *data01 = [PNScatterChartData new]; data01.strokeColor = PNGreen; data01.fillColor = PNFreshGreen; data01.size = 2; data01.itemCount = [[data01Array objectAtIndex:0] count]; data01.inflexionPointStyle = PNScatterChartPointStyleCircle; __block NSMutableArray *XAr1 = [NSMutableArray arrayWithArray:[data01Array objectAtIndex:0]]; __block NSMutableArray *YAr1 = [NSMutableArray arrayWithArray:[data01Array objectAtIndex:1]]; data01.getData = ^(NSUInteger index) { CGFloat xValue = [[XAr1 objectAtIndex:index] floatValue]; CGFloat yValue = [[YAr1 objectAtIndex:index] floatValue]; return [PNScatterChartDataItem dataItemWithX:xValue AndWithY:yValue]; }; [scatterChart setup]; self.scatterChart.chartData = @[data01]; /*** this is for drawing line to compare CGPoint start = CGPointMake(20, 35); CGPoint end = CGPointMake(80, 45); [scatterChart drawLineFromPoint:start ToPoint:end WithLineWith:2 AndWithColor:PNBlack]; ***/ scatterChart.delegate = self;

 

Legend

Legend has been added to PNChart for Line and Pie Charts. Legend items position can be stacked or in series.

#import "PNChart.h"

//For Line Chart

//Add Line Titles for the Legend data01.dataTitle = @"Alpha"; data02.dataTitle = @"Beta Beta Beta Beta"; //Build the legend self.lineChart.legendStyle = PNLegendItemStyleSerial; self.lineChart.legendFontSize = 12.0; UIView *legend = [self.lineChart getLegendWithMaxWidth:320]; //Move legend to the desired position and add to view [legend setFrame:CGRectMake(100, 400, legend.frame.size.width, legend.frame.size.height)]; [self.view addSubview:legend]; //For Pie Chart //Build the legend self.pieChart.legendStyle = PNLegendItemStyleStacked; self.pieChart.legendFontSize = 12.0; UIView *legend = [self.pieChart getLegendWithMaxWidth:200]; //Move legend to the desired position and add to view [legend setFrame:CGRectMake(130, 350, legend.frame.size.width, legend.frame.size.height)]; [self.view addSubview:legend];

 

Update Value

Now it's easy to update value in real time

实时更新数据也是很简单的

if ([self.title isEqualToString:@"Line Chart"]) { // Line Chart #1 NSArray * data01Array = @[@(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300)]; 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 = @[@(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300)]; 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 setXLabels:@[@"DEC 1",@"DEC 2",@"DEC 3",@"DEC 4",@"DEC 5",@"DEC 6",@"DEC 7"]]; [self.lineChart updateChartData:@[data01, data02]]; } else if ([self.title isEqualToString:@"Bar Chart"]) { [self.barChart setXLabels:@[@"Jan 1",@"Jan 2",@"Jan 3",@"Jan 4",@"Jan 5",@"Jan 6",@"Jan 7"]]; [self.barChart updateChartData:@[@(arc4random() % 30),@(arc4random() % 30),@(arc4random() % 30),@(arc4random() % 30),@(arc4random() % 30),@(arc4random() % 30),@(arc4random() % 30)]]; } else if ([self.title isEqualToString:@"Circle Chart"]) { [self.circleChart updateChartByCurrent:@(arc4random() % 100)]; }

 

Callback

#import "PNChart.h"

//For LineChart

lineChart.delegate = self;

//For DelegateMethod


-(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); } 

 

License

This code is distributed under the terms and conditions of the MIT license.

 

SpecialThanks

@lexrus CocoaPods Spec ZhangHang Pie Chart MrWooj Scatter Chart

目录
相关文章
|
15天前
|
人工智能 JSON API
全网刷屏的 Jev 模型正式开放!一手实战测评 + 保姆级教程
全网爆火的 Jev 模型是什么?有什么用?怎么使用?怎么接入 AI 编程工具?效果真的好么?傻子可懂的 Jev 保姆级实战教程 + 项目实战测评来啦
8163 15
|
14天前
|
人工智能 并行计算 PyTorch
秋叶 ComfyUI 2026 整合包 v3.2 完整部署教程:Python 3.13 + Torch 2.13 全栈升级
秋叶aaaki ComfyUI 2026年8月整合包v3.2正式发布!全面升级Python 3.13.11、PyTorch 2.13.0+cu130及ComfyUI v0.30.2,原生支持MiniMax H3、Wan 2.2、Qwen-Image-2.1等2026主流音视频/图像模型,解压即用,无需环境配置。
2351 13
|
13天前
|
人工智能 测试技术 API
最近全网爆火的 Jev 到底是什么?适合干什么、怎么用,一篇讲透!
Jev是TypeSafe AI推出的“系统一模型”,不生成文本,专做毫秒级结构化决策:Choice(多选)、Score(打分)、Noul(是非概率)。响应快193倍、成本低444倍,适合工单路由、内容审核、测试定级等高频判断场景。
1846 4
最近全网爆火的 Jev 到底是什么?适合干什么、怎么用,一篇讲透!
|
12天前
|
人工智能 编解码 并行计算
MiniMax-H3 一键整合包技术文档:8G 显存运行 AI 漫剧制作 —— 角色替换 / 动作迁移 / 文图生视频部署与调参指南
MiniMax H3 是 MiniMax 开源的全模态视频生成模型,支持文/图/音/视多条件输入,输出最高2K、15秒带双声道音频视频。本文档详述其Int8量化版在8GB显存下的本地一键部署、三段式工作流(EDIT/REPLACE/CONTINUE)、参数调优及常见问题排查。(239字)
|
8天前
|
人工智能 Linux 开发者
【2026国内使用】Codex安装过程一篇讲透(Win/Mac/Linux全支持)
Codex是OpenAI推出的AI编程智能体,可读取本地项目、理解需求并自动修改代码。支持桌面GUI、命令行(CLI)及VS Code/Cursor插件三种形态,覆盖可视化操作、终端高效开发与编辑器无缝集成场景,助开发者用自然语言驱动编码全流程。(239字)
【2026国内使用】Codex安装过程一篇讲透(Win/Mac/Linux全支持)
|
8天前
|
人工智能 JSON 编解码
【2026最新版】ComfyUI本地部署教程,新手也能看懂!
ComfyUI是本地运行的AI绘画工具,采用节点式工作流设计:通过拖拽连接“加载模型”“提示词编码”“采样”“解码”等模块,实现高度可控的文生图。新手推荐使用秋叶整合包,一键启动、内置模型管理与插件安装器,轻松上手。(239字)
|
22天前
|
缓存 IDE Java
【保姆级】Android Studio下载、安装和汉化教程(2026最新)
Android Studio 是 Google 官方推出的免费 Android 应用开发集成环境,基于 IntelliJ IDEA,内置模拟器、调试器、性能分析及 Compose 界面工具,功能全面,文档丰富,是安卓开发首选工具。(239字)
2342 1

热门文章

最新文章