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

目录
相关文章
|
9月前
|
开发框架 .NET C#
零基础如何自学C#?
零基础如何自学C#?
115 0
|
7月前
|
弹性计算 开发工具 Android开发
阿里云APP备案操作流程_亲测
阿里云APP备案操作流程_亲自测试,一共6个步骤即可完成APP备案
11622 2
|
8天前
|
人工智能 自然语言处理 API
深入浅出LangChain与智能Agent:构建下一代AI助手
LangChain为大型语言模型提供了一种全新的搭建和集成方式,通过这个强大的框架,我们可以将复杂的技术任务简化,让创意和创新更加易于实现。本文从LangChain是什么到LangChain的实际案例到智能体的快速发展做了全面的讲解。
279547 52
深入浅出LangChain与智能Agent:构建下一代AI助手
|
9天前
|
设计模式 人工智能 JSON
一文掌握大模型提示词技巧:从战略到战术
本文将用通俗易懂的语言,带你从战略(宏观)和战术(微观)两个层次掌握大模型提示词的常见技巧,真正做到理论和实践相结合,占领 AI 运用的先机。
237787 4
|
9天前
|
NoSQL Cloud Native Redis
Redis核心开发者的新征程:阿里云与Valkey社区的技术融合与创新
阿里云瑶池数据库团队后续将持续参与Valkey社区,如过往在Redis社区一样耕耘,为开源社区作出持续贡献。
Redis核心开发者的新征程:阿里云与Valkey社区的技术融合与创新
|
9天前
|
关系型数据库 分布式数据库 数据库
PolarDB闪电助攻,《香肠派对》百亿好友关系实现毫秒级查询
PolarDB分布式版助力《香肠派对》实现百亿好友关系20万QPS的毫秒级查询。
PolarDB闪电助攻,《香肠派对》百亿好友关系实现毫秒级查询
|
3天前
|
机器人 Linux API
基于Ollama+AnythingLLM轻松打造本地大模型知识库
Ollama是开源工具,简化了在本地运行大型语言模型(ile优化模型运行,支持GPU使用和热加载。它轻量、易用,可在Mac和Linux上通过Docker快速部署。AnythingLLM是Mintplex Labs的文档聊天机器人,支持多用户、多种文档格式,提供对话和查询模式,内置向量数据库,可高效管理大模型和文档。它也是开源的,能与Ollama结合使用,提供安全、低成本的LLM体验。这两款工具旨在促进本地高效利用和管理LLMs。
93867 19
|
10天前
|
消息中间件 Cloud Native Serverless
RocketMQ 事件驱动:云时代的事件驱动有啥不同?
本文深入探讨了云时代 EDA 的新内涵及它在云时代再次流行的主要驱动力,包括技术驱动力和商业驱动力,随后重点介绍了 RocketMQ 5.0 推出的子产品 EventBridge,并通过几个云时代事件驱动的典型案例,进一步叙述了云时代事件驱动的常见场景和最佳实践。
246780 2
|
8天前
|
物联网 PyTorch 测试技术
手把手教你捏一个自己的Agent
Modelscope AgentFabric是一个基于ModelScope-Agent的交互式智能体应用,用于方便地创建针对各种现实应用量身定制智能体,目前已经在生产级别落地。
|
11天前
|
弹性计算 安全 API
访问控制(RAM)|云上安全使用AccessKey的最佳实践
集中管控AK/SK的生命周期,可以极大降低AK/SK管理和使用成本,同时通过加密和轮转的方式,保证AK/SK的安全使用,本次分享为您介绍产品原理,以及具体的使用步骤。
101886 3