A simple and beautiful chart lib used in Piner and CoinsMan for iOS

Related tags

Charts PNChart
Overview

PNChart

Build Status

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

#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.

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.

lineChartData.rangeColors = @[
        [[PNLineChartColorRange alloc] initWithRange:NSMakeRange(10, 30) color:[UIColor redColor]],
        [[PNLineChartColorRange alloc] initWithRange:NSMakeRange(100, 200) color:[UIColor purpleColor]]
];
#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;
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;
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];

Grid Lines

Grid lines have been added to PNChart for Line Chart.

lineChart.showYGridLines = YES;
lineChart.yGridLinesColor = [UIColor grayColor];

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;

Animation

Animation is enabled by default when drawing all charts. It can be disabled by setting displayAnimation = NO.

#import "PNChart.h"

//For LineChart

lineChart.displayAnimation = NO;
//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

Comments
  • UICountingLabel/UICountingLabel.h fie not found on master branch

    UICountingLabel/UICountingLabel.h fie not found on master branch

    git clone https://github.com/kevinzhow/PNChart.git

    1、 pod update XCode6 open PNChartDemo.xcworkspace command+b XCode6 reminder me that UICountingLabel/UICountingLabel.h fie not found

    2、 add source 'https://github.com/CocoaPods/Specs.git' to the top of Podfile: pod uopate XCode6 open PNChartDemo.xcworkspace command+b XCode6 still reminder me that UICountingLabel/UICountingLabel.h fie not found

    opened by ghost 8
  • Error Running Code

    Error Running Code

    I did everything as instructed(edited pod file, did pod install), but I'm getting this error running your demo code: ld: library not found for -lPods clang: error: linker command failed with exit code 1 (use -v to see invocation)

    Log:

    Ld /Users/henrykatz/Library/Developer/Xcode/DerivedData/PNChartDemo-hjfbbjwccfkwwngvtswkbyoqjmoi/Build/Products/Debug-iphonesimulator/PNChartDemo.app/PNChartDemo normal i386 cd /Users/henrykatz/Downloads/PNChart-master export IPHONEOS_DEPLOYMENT_TARGET=6.0 export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk -L/Users/henrykatz/Library/Developer/Xcode/DerivedData/PNChartDemo-hjfbbjwccfkwwngvtswkbyoqjmoi/Build/Products/Debug-iphonesimulator -F/Users/henrykatz/Library/Developer/Xcode/DerivedData/PNChartDemo-hjfbbjwccfkwwngvtswkbyoqjmoi/Build/Products/Debug-iphonesimulator -filelist /Users/henrykatz/Library/Developer/Xcode/DerivedData/PNChartDemo-hjfbbjwccfkwwngvtswkbyoqjmoi/Build/Intermediates/PNChartDemo.build/Debug-iphonesimulator/PNChartDemo.build/Objects-normal/i386/PNChartDemo.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -ObjC -framework CoreGraphics -framework Foundation -framework QuartzCore -framework UIKit -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=6.0 -framework QuartzCore -framework CoreGraphics -framework UIKit -framework Foundation -lPods -Xlinker -dependency_info -Xlinker /Users/henrykatz/Library/Developer/Xcode/DerivedData/PNChartDemo-hjfbbjwccfkwwngvtswkbyoqjmoi/Build/Intermediates/PNChartDemo.build/Debug-iphonesimulator/PNChartDemo.build/Objects-normal/i386/PNChartDemo_dependency_info.dat -o /Users/henrykatz/Library/Developer/Xcode/DerivedData/PNChartDemo-hjfbbjwccfkwwngvtswkbyoqjmoi/Build/Products/Debug-iphonesimulator/PNChartDemo.app/PNChartDemo

    opened by hkfgo 8
  • When I use the barChart , my code crashed with exc_bad_access

    When I use the barChart , my code crashed with exc_bad_access

    It seems that the code: [barChart strokeChart] , was trying to release some memory that has already been releaseed.

    I can't figure it, so I post it.

    Have a nice day :-).

    opened by vesper305 8
  • CocoaPods

    CocoaPods

    In your project description you say that the minimum requirement is iOS 6, but when I install from CocoaPods it says:

    [!] The platform of the target Pods (iOS 7.0) is not compatible with PNChart (0.8.2) which has a minimum requirement of iOS 8.0.

    Can you please fix this?

    Thanks, José Teixeira

    opened by jmteixeira 6
  • LineChart ylabels

    LineChart ylabels

    I have an issue concerning the labels on the y-axis of the LineChart.

    For some reason, I have weird numbers appearing below the actual labels of my LineChart.

    See the image here: (0 - 7 are my actual numbers, the large numbers below are the ones I'm talking about) bildschirmfoto 2014-12-12 um 21 34 18

    Anyone know how to fix this?

    opened by PhilJay 6
  • Adding in all the charts to the app?

    Adding in all the charts to the app?

    Hi just downloaded and clicked the project and it only has the line view. How do I add all other charts to the other views?

    Or have I just totally missed it being a newbie on here.

    Thanks for sharing!!!

    opened by STRND 6
  • Multi Line Chart with different number of x labels

    Multi Line Chart with different number of x labels

    Is there a way to have Multiple Lines Chart where each line will have different number of x labels. Currently this causes it to crash.

    For example Line 1 has 20 x labels but Line 2 has only 10 x labels points.

    Any suggestions are appreciated.

    opened by Sun3 5
  • Multiple Lines on a Line Graph?

    Multiple Lines on a Line Graph?

    It would be awesome if there could be an option for more than 1 line on a line graph! This would really make this project amazing!

    Same with bar charts!

    sample

    opened by vicc 5
  • Fix warning in block declaration from UICountingLabel

    Fix warning in block declaration from UICountingLabel

    This PR updates UICountingLabel dependency to the latest version to remove the warning of block declaration. More info here.

    • [x] Update CocoaPods to 1.3.1
    • [x] Bump target to iOS 7.0 to be able to use latest UICountingLabel
    • [x] Update UICountingLabel to v1.4.1
    • [x] Hide 'Animations' label on Scatter Chart demo
    opened by 0mega 4
  • LineChart:the first point cannot be drawn at the right position due to the calculateChartPath function

    LineChart:the first point cannot be drawn at the right position due to the calculateChartPath function

    In PNLineChart.m, the innerGrade in calculateChartPath() is calculated as: innerGrade = (yValue - _yValueMin) / (_yValueMax - _yValueMin) == 0 ? 0.5 : (yValue - _yValueMin) / (_yValueMax - _yValueMin); How is the '0.5' defined, why? I draw the LineChart in my project, the first point of the line cannot be drawn at the right position. If I modify the innerGrade as following: innerGrade = (yValue - _yValueMin) / (_yValueMax - _yValueMin) It seems right.

    opened by fromnow 4
  • Legend

    Legend

    I have extended your awesome PNChart to create also a legend. Actually I have implemented the legend for Line and Pie chart. Added some mini customization to Pie Chart like absolute values and no description (because they appear on legend).

    Thanks

    opened by sanandrea 4
  • PNChart display issuer while using YogaKit

    PNChart display issuer while using YogaKit

    I am trying to use both PNChart and Yogakit, but the chart could not display correctly. Below is the code in my projct.

    UIView *root = self.view;
    [root configureLayoutWithBlock:^(YGLayout * _Nonnull layout) {
        layout.isEnabled = YES;
        layout.flexDirection = YGFlexDirectionColumn;
    }];
    
    PNLineChart * lineChart = [[PNLineChart alloc] init];
    lineChart.backgroundColor = UIColor.whiteColor;
    [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];
    
    [lineChart configureLayoutWithBlock:^(YGLayout * _Nonnull layout) {
        layout.isEnabled = YES;
        layout.flex = 7;
    }];
    
    [root addSubview:lineChart];
    

    Is it possible to set the layout with yoga in pnchart? I am fairly new in ios development, please forgive me if I made it unclear, thank you.

    opened by Gin6x 0
  • PNChart-master/Pods/Target Support Files/Pods-PNChartDemo/Pods-PNChartDemo.debug.xcconfig: unable to open file (in target

    PNChart-master/Pods/Target Support Files/Pods-PNChartDemo/Pods-PNChartDemo.debug.xcconfig: unable to open file (in target "PNChartDemo" in project "PNChartDemo") (in target 'PNChartDemo')

    PNChart-master/Pods/Target Support Files/Pods-PNChartDemo/Pods-PNChartDemo.debug.xcconfig: unable to open file (in target "PNChartDemo" in project "PNChartDemo") (in target 'PNChartDemo')

    opened by ange521 0
Releases(0.5)
Owner
Kevin
Code Design and Crafts
Kevin
Simple and intuitive iOS chart library. Contribution graph, clock chart, and bar chart.

TEAChart Simple and intuitive iOS chart library, for Pomotodo app. Contribution graph, clock chart, and bar chart. Supports Storyboard and is fully ac

柳东原 · Dongyuan Liu 1.2k Nov 29, 2022
SwiftUI library to easily render diagrams given a tree of objects. Similar to ring chart, sunburst chart, multilevel pie chart.

Swift Sunburst Diagram Sunburst diagram is a library written with SwiftUI to easily render diagrams given a tree of objects. Similar to ring chart, su

Ludovic Landry 494 Dec 19, 2022
A simple and animated Pie Chart for your iOS app.

XYPieChart XYPieChart is an simple and easy-to-use pie chart for iOS app. It started from a Potion Project which needs an animated pie graph without i

XY Feng 1.7k Sep 6, 2022
A simple pie chart for iOS.

EGPieChart Installation EGPieChart is available through CocoaPods. To install it, simply add the following line to your Podfile: pod 'EGPieChart' manu

Ethan Guan 3 Nov 29, 2021
iOS/iPhone/iPad Chart, Graph. Event handling and animation supported.

#EChart A highly extendable, easy to use chart with event handling, animation supported. ##Test How To Use Download and run the EChartDemo project is

Scott Zhu 646 Dec 27, 2022
iOS Chart. Support animation, click, scroll, area highlight.

XJYChart XJYChart - A High-performance, Elegant, Easy-to-integrate Charting Framework. The Best iOS Objc Charts. chart more beautiful support chart sc

junyixie 868 Nov 16, 2022
FSLineChart A line chart library for iOS.

FSLineChart A line chart library for iOS. Screenshots Installing FSLineChart Add the contents of the FSLineChart project to your directory or simply a

Arthur 856 Nov 24, 2022
an iOS open source Radar Chart implementation

JYRadarChart an open source iOS Radar Chart implementation ##Screenshots Requirements Xcode 5 or higher iOS 5.0 or higher ARC CoreGraphics.framework D

Johnny Wu 416 Dec 31, 2022
Easy to use Spider (Radar) Chart library for iOS written in Swift.

DDSpiderChart Easy to use Spider (Radar) Chart library for iOS written in Swift. Requirements iOS 8.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+ Xcode

Deniz Adalar 82 Nov 14, 2022
Line Chart library for iOS written in Swift

Swift LineChart Usage var lineChart = LineChart() lineChart.addLine([3, 4, 9, 11, 13, 15]) Features Super simple Highly customizable Auto scaling Touc

Mirco Zeiss 601 Nov 15, 2022
Core Charts | Basic Scrollable Chart Library for iOS

Core Charts | Basic Chart Library for iOS HCoreBarChart VCoreBarChart Requirements Installation Usage Appearance Customization Getting Started You nee

Çağrı ÇOLAK 71 Nov 17, 2022
candlestick chart for ios

###Licenses (The MIT License) Copyright ©2012 zhiyu zheng all rights reserved. Permission is hereby granted, free of charge, to any person obtaining a

ZhiYu 962 Oct 17, 2022
MSBBarChart is an easy to use bar chart library for iOS

MSBBarChart MSBBarChart is an easy to use bar chart library for iOS. Usage if you want to hide label above bar barChart.setOptions([.isHiddenLabelAbov

misyobun 45 May 3, 2022
A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.

⚡ A powerful & easy to use chart library for Android ⚡ Charts is the iOS version of this library Table of Contents Quick Start Gradle Maven Documentat

Philipp Jahoda 36k Jan 5, 2023
This is pie chart that is very easy to use and customizable design.

CSPieChart Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation CSPieCh

iOSCS 40 Nov 29, 2022
JTChartView is the new lightweight and fully customizable solution to draw a chart

JTChartView JTChartView is the new lightweight and fully customizable solution to draw a curve and fill the space underneath it with a gradient. The r

Jakub Truhlář 124 Sep 7, 2022
Using Swift Charts and Voiceover Chart Descriptor to compose music. 🤯

Chart de lune ?? Using Swift Charts and Voiceover Chart Descriptor to compose music. ?? Image source: https://hadikarimi.com/portfolio/claude-debussy-

An Trinh 31 Nov 21, 2022
TKRadarChart - A customizable radar chart in Swift

TKRadarChart A customizable radar chart in Swift Requirements iOS 8.0+ Xcode 9.0 Swift 4.0 Installation CocoaPods You can use CocoaPods to install TKR

TBXark 203 Dec 28, 2022
SwiftUI Bar Chart

SwiftUI BarChart Lightweight and easy to use SwiftUI chart library for all Apple platforms Features Scaling on both axes Fully customizable axes (labe

Roman Baitaliuk 158 Jan 6, 2023