{"id":837,"url":"https://github.com/kevinzhow/PNChart","last_synced_at":"2025-08-13T07:33:15.164Z","repository":{"id":11676992,"uuid":"14187079","full_name":"kevinzhow/PNChart","owner":"kevinzhow","description":"A simple and beautiful chart lib used in Piner and CoinsMan for iOS","archived":false,"fork":false,"pushed_at":"2018-07-02T12:43:03.000Z","size":676,"stargazers_count":9692,"open_issues_count":174,"forks_count":1756,"subscribers_count":326,"default_branch":"master","last_synced_at":"2025-08-04T10:39:59.291Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevinzhow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-06T22:06:17.000Z","updated_at":"2025-08-01T11:23:34.000Z","dependencies_parsed_at":"2022-08-07T06:16:30.005Z","dependency_job_id":null,"html_url":"https://github.com/kevinzhow/PNChart","commit_stats":null,"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"purl":"pkg:github/kevinzhow/PNChart","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinzhow%2FPNChart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinzhow%2FPNChart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinzhow%2FPNChart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinzhow%2FPNChart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinzhow","download_url":"https://codeload.github.com/kevinzhow/PNChart/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinzhow%2FPNChart/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270204432,"owners_count":24544674,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-13T02:00:09.904Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:15:32.587Z","updated_at":"2025-08-13T07:33:14.865Z","avatar_url":"https://github.com/kevinzhow.png","language":"Objective-C","funding_links":[],"categories":["Charts","Charting","awesome-ios ##","Objective-C","iOS tools","UI","IOS 或 OSX","9. 其他与展望","Objective-C  Stars 1000以内排名整理","iOS"],"sub_categories":["Misc","Other free courses","Getting Started","5. 参考材料","Charts"],"readme":"# PNChart\n\n[![Build Status](https://travis-ci.org/kevinzhow/PNChart.png?branch=master)](https://travis-ci.org/kevinzhow/PNChart)\n\nYou can also find swift version at here https://github.com/kevinzhow/PNChart-Swift\n\nA simple and beautiful chart lib with **animation** used in [Piner](https://itunes.apple.com/us/app/piner/id637706410) and [CoinsMan](https://itunes.apple.com/us/app/coinsman/id772163893) for iOS\n\n[![](https://s3.amazonaws.com/farshid.ghods.github/pnchart-gif.gif)](https://s3.amazonaws.com/farshid.ghods.github/pnchart-gif.gif)\n\n## Requirements\n\nPNChart works on iOS 7.0+ and is compatible with ARC projects.\nIf you need support for iOS 6, use PNChart \u003c= 0.8.1. Note that 0.8.2 supports iOS 8.0+ only, 0.8.3 and newer supports iOS 7.0+.\n\nIt depends on the following Apple frameworks, which should already be included with most Xcode templates:\n\n* Foundation.framework\n* UIKit.framework\n* CoreGraphics.framework\n* QuartzCore.framework\n\nYou will need LLVM 3.0 or later in order to build PNChart.\n\n\n## Usage\n\n### Cocoapods\n\n[CocoaPods](http://cocoapods.org) is the recommended way to add PNChart to your project.\n\n1. Add a pod entry for PNChart to your Podfile `pod 'PNChart'`\n2. Install the pod(s) by running `pod install`.\n3. Include PNChart wherever you need it with `#import \"PNChart.h\"`.\n\n\n### Copy the PNChart folder to your project\n\n```objective-c\n#import \"PNChart.h\"\n\n//For Line Chart\nPNLineChart * lineChart = [[PNLineChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)];\n[lineChart setXLabels:@[@\"SEP 1\",@\"SEP 2\",@\"SEP 3\",@\"SEP 4\",@\"SEP 5\"]];\n\n// Line Chart No.1\nNSArray * data01Array = @[@60.1, @160.1, @126.4, @262.2, @186.2];\nPNLineChartData *data01 = [PNLineChartData new];\ndata01.color = PNFreshGreen;\ndata01.itemCount = lineChart.xLabels.count;\ndata01.getData = ^(NSUInteger index) {\n    CGFloat yValue = [data01Array[index] floatValue];\n    return [PNLineChartDataItem dataItemWithY:yValue];\n};\n// Line Chart No.2\nNSArray * data02Array = @[@20.1, @180.1, @26.4, @202.2, @126.2];\nPNLineChartData *data02 = [PNLineChartData new];\ndata02.color = PNTwitterColor;\ndata02.itemCount = lineChart.xLabels.count;\ndata02.getData = ^(NSUInteger index) {\n    CGFloat yValue = [data02Array[index] floatValue];\n    return [PNLineChartDataItem dataItemWithY:yValue];\n};\n\nlineChart.chartData = @[data01, data02];\n[lineChart strokeChart];\n```\n\n\nYou can choose to show smooth lines.\n\n```objective-c\nlineChart.showSmoothLines = YES;\n```\n\n[![](https://s3.amazonaws.com/farshid.ghods.github/pnchart-linechart-smooth.png)](https://s3.amazonaws.com/farshid.ghods.github/pnchart-linechart-smooth.png)\n\n\nYou 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.\n\n\n[![](https://s3.amazonaws.com/farshid.ghods.github/pnchart-rangecolors-2.png)](https://s3.amazonaws.com/farshid.ghods.github/pnchart-rangecolors-2.png)\n\n\n```objective-c\nlineChartData.rangeColors = @[\n        [[PNLineChartColorRange alloc] initWithRange:NSMakeRange(10, 30) color:[UIColor redColor]],\n        [[PNLineChartColorRange alloc] initWithRange:NSMakeRange(100, 200) color:[UIColor purpleColor]]\n];\n```\n\n```objective-c\n#import \"PNChart.h\"\n\n//For BarC hart\nPNBarChart * barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)];\n[barChart setXLabels:@[@\"SEP 1\",@\"SEP 2\",@\"SEP 3\",@\"SEP 4\",@\"SEP 5\"]];\n[barChart setYValues:@[@1,  @10, @2, @6, @3]];\n[barChart strokeChart];\n\n```\n\n```objective-c\n#import \"PNChart.h\"\n\n//For Circle Chart\n\nPNCircleChart * circleChart = [[PNCircleChart alloc] initWithFrame:CGRectMake(0, 80.0, SCREEN_WIDTH, 100.0) total:[NSNumber numberWithInt:100] current:[NSNumber numberWithInt:60] clockwise:NO shadow:NO];\ncircleChart.backgroundColor = [UIColor clearColor];\n[circleChart setStrokeColor:PNGreen];\n[circleChart strokeChart];\n\n```\n\n\n```objective-c\n# import \"PNChart.h\"\n//For Pie Chart\nNSArray *items = @[[PNPieChartDataItem dataItemWithValue:10 color:PNRed],\n                           [PNPieChartDataItem dataItemWithValue:20 color:PNBlue description:@\"WWDC\"],\n                           [PNPieChartDataItem dataItemWithValue:40 color:PNGreen description:@\"GOOL I/O\"],\n                           ];\n\n\n\nPNPieChart *pieChart = [[PNPieChart alloc] initWithFrame:CGRectMake(40.0, 155.0, 240.0, 240.0) items:items];\npieChart.descriptionTextColor = [UIColor whiteColor];\npieChart.descriptionTextFont  = [UIFont fontWithName:@\"Avenir-Medium\" size:14.0];\n[pieChart strokeChart];\n```\n\n```objective-c\n# import \"PNChart.h\"\n//For Scatter Chart\n\nPNScatterChart *scatterChart = [[PNScatterChart alloc] initWithFrame:CGRectMake(SCREEN_WIDTH /6.0 - 30, 135, 280, 200)];\n[scatterChart setAxisXWithMinimumValue:20 andMaxValue:100 toTicks:6];\n[scatterChart setAxisYWithMinimumValue:30 andMaxValue:50 toTicks:5];\n\nNSArray * data01Array = [self randomSetOfObjects];\nPNScatterChartData *data01 = [PNScatterChartData new];\ndata01.strokeColor = PNGreen;\ndata01.fillColor = PNFreshGreen;\ndata01.size = 2;\ndata01.itemCount = [[data01Array objectAtIndex:0] count];\ndata01.inflexionPointStyle = PNScatterChartPointStyleCircle;\n__block NSMutableArray *XAr1 = [NSMutableArray arrayWithArray:[data01Array objectAtIndex:0]];\n__block NSMutableArray *YAr1 = [NSMutableArray arrayWithArray:[data01Array objectAtIndex:1]];\ndata01.getData = ^(NSUInteger index) {\n    CGFloat xValue = [[XAr1 objectAtIndex:index] floatValue];\n    CGFloat yValue = [[YAr1 objectAtIndex:index] floatValue];\n    return [PNScatterChartDataItem dataItemWithX:xValue AndWithY:yValue];\n};\n\n[scatterChart setup];\nself.scatterChart.chartData = @[data01];\n/***\nthis is for drawing line to compare\nCGPoint start = CGPointMake(20, 35);\nCGPoint end = CGPointMake(80, 45);\n[scatterChart drawLineFromPoint:start ToPoint:end WithLineWith:2 AndWithColor:PNBlack];\n***/\nscatterChart.delegate = self;\n```\n\n#### Legend\n\nLegend has been added to PNChart for Line and Pie Charts. Legend items position can be stacked or in series.\n\n```objective-c\n#import \"PNChart.h\"\n\n//For Line Chart\n\n//Add Line Titles for the Legend\ndata01.dataTitle = @\"Alpha\";\ndata02.dataTitle = @\"Beta Beta Beta Beta\";\n\n//Build the legend\nself.lineChart.legendStyle = PNLegendItemStyleSerial;\nUIView *legend = [self.lineChart getLegendWithMaxWidth:320];\n\n//Move legend to the desired position and add to view\n[legend setFrame:CGRectMake(100, 400, legend.frame.size.width, legend.frame.size.height)];\n[self.view addSubview:legend];\n\n\n//For Pie Chart\n\n//Build the legend\nself.pieChart.legendStyle = PNLegendItemStyleStacked;\nUIView *legend = [self.pieChart getLegendWithMaxWidth:200];\n\n//Move legend to the desired position and add to view\n[legend setFrame:CGRectMake(130, 350, legend.frame.size.width, legend.frame.size.height)];\n[self.view addSubview:legend];\n```\n\n#### Grid Lines\n\nGrid lines have been added to PNChart for Line Chart.\n\n```objective-c\nlineChart.showYGridLines = YES;\nlineChart.yGridLinesColor = [UIColor grayColor];\n```\n\n[![](https://s3.amazonaws.com/farshid.ghods.github/pnchart-gridline.png)](https://s3.amazonaws.com/farshid.ghods.github/pnchart-gridline.png)\n\n#### Update Value\n\nNow it's easy to update value in real time\n\n```objective-c\nif ([self.title isEqualToString:@\"Line Chart\"]) {\n\n    // Line Chart #1\n    NSArray * data01Array = @[@(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300)];\n    PNLineChartData *data01 = [PNLineChartData new];\n    data01.color = PNFreshGreen;\n    data01.itemCount = data01Array.count;\n    data01.inflexionPointStyle = PNLineChartPointStyleTriangle;\n    data01.getData = ^(NSUInteger index) {\n        CGFloat yValue = [data01Array[index] floatValue];\n        return [PNLineChartDataItem dataItemWithY:yValue];\n    };\n\n    // Line Chart #2\n    NSArray * data02Array = @[@(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300), @(arc4random() % 300)];\n    PNLineChartData *data02 = [PNLineChartData new];\n    data02.color = PNTwitterColor;\n    data02.itemCount = data02Array.count;\n    data02.inflexionPointStyle = PNLineChartPointStyleSquare;\n    data02.getData = ^(NSUInteger index) {\n        CGFloat yValue = [data02Array[index] floatValue];\n        return [PNLineChartDataItem dataItemWithY:yValue];\n    };\n\n    [self.lineChart setXLabels:@[@\"DEC 1\",@\"DEC 2\",@\"DEC 3\",@\"DEC 4\",@\"DEC 5\",@\"DEC 6\",@\"DEC 7\"]];\n    [self.lineChart updateChartData:@[data01, data02]];\n\n}\nelse if ([self.title isEqualToString:@\"Bar Chart\"])\n{\n    [self.barChart setXLabels:@[@\"Jan 1\",@\"Jan 2\",@\"Jan 3\",@\"Jan 4\",@\"Jan 5\",@\"Jan 6\",@\"Jan 7\"]];\n    [self.barChart updateChartData:@[@(arc4random() % 30),@(arc4random() % 30),@(arc4random() % 30),@(arc4random() % 30),@(arc4random() % 30),@(arc4random() % 30),@(arc4random() % 30)]];\n}\nelse if ([self.title isEqualToString:@\"Circle Chart\"])\n{\n    [self.circleChart updateChartByCurrent:@(arc4random() % 100)];\n}\n```\n\n#### Callback\n\n```objective-c\n#import \"PNChart.h\"\n\n//For LineChart\n\nlineChart.delegate = self;\n\n\n```\n\n#### Animation\n\nAnimation is enabled by default when drawing all charts. It can be disabled by setting `displayAnimation = NO`.\n\n```objective-c\n#import \"PNChart.h\"\n\n//For LineChart\n\nlineChart.displayAnimation = NO;\n\n```\n\n\n\n```objective-c\n\n//For DelegateMethod\n\n\n-(void)userClickedOnLineKeyPoint:(CGPoint)point lineIndex:(NSInteger)lineIndex pointIndex:(NSInteger)pointIndex{\n    NSLog(@\"Click Key on line %f, %f line index is %d and point index is %d\",point.x, point.y,(int)lineIndex, (int)pointIndex);\n}\n\n-(void)userClickedOnLinePoint:(CGPoint)point lineIndex:(NSInteger)lineIndex{\n    NSLog(@\"Click on line %f, %f, line index is %d\",point.x, point.y, (int)lineIndex);\n}\n\n```\n\n\n## License\n\nThis code is distributed under the terms and conditions of the [MIT license](LICENSE).\n\n## SpecialThanks\n\n[@lexrus](http://twitter.com/lexrus)  CocoaPods Spec\n[ZhangHang](http://zhanghang.github.com)  Pie Chart\n[MrWooj](https://github.com/MrWooJ) Scatter Chart\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinzhow%2FPNChart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinzhow%2FPNChart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinzhow%2FPNChart/lists"}