Convert Figma logo to code with AI

kevinzhow logoPNChart

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

9,714
1,763
9,714
174

Top Related Projects

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

📈📊🚀🚀🚀An elegant modern declarative data visualization chart framework for iOS, iPadOS and macOS. Extremely powerful, supports line, spline, area, areaspline, column, bar, pie, scatter, angular gauges, arearange, areasplinerange, columnrange, bubble, box plot, error bars, funnel, waterfall and polar chart types. 极其精美而又强大的现代化声明式数据可视化图表框架,支持柱状图、条形图、折线图、曲线图、折线填充图、曲线填充图、气泡图、扇形图、环形图、散点图、雷达图、混合图等各种类型的多达几十种的信息图图表,完全满足工作所需.

Android Graph Library for creating zoomable and scrollable line and bar graphs.

Interactive plotting library for .NET

Quick Overview

PNChart is a simple and beautiful chart library for iOS. It provides an easy way to create animated line charts, bar charts, pie charts, and more. The library is designed to be lightweight and customizable, making it suitable for various iOS applications.

Pros

  • Easy to use and integrate into iOS projects
  • Supports multiple chart types (line, bar, pie, circle, etc.)
  • Smooth animations for data visualization
  • Customizable appearance and styling options

Cons

  • Limited to iOS platform only
  • May not be suitable for complex or highly specialized chart requirements
  • Documentation could be more comprehensive
  • Not actively maintained (last update was in 2017)

Code Examples

Creating a line chart:

let lineChart = PNLineChart(frame: CGRect(x: 0, y: 135, width: 320, height: 200))
lineChart.yLabelFormat = "%1.1f"
lineChart.xLabels = ["SEP 1","SEP 2","SEP 3","SEP 4","SEP 5","SEP 6","SEP 7"]
lineChart.strokeChart()

self.view.addSubview(lineChart)

Creating a bar chart:

let barChart = PNBarChart(frame: CGRect(x: 0, y: 135, width: 320, height: 200))
barChart.yLabelFormatter = {(yValue: CGFloat) -> String in
    return String(format: "%.1f", yValue)
}
barChart.yValues = [1, 2, 3, 4, 5, 6, 7]
barChart.strokeChart()

self.view.addSubview(barChart)

Creating a pie chart:

let pieChart = PNPieChart(frame: CGRect(x: 40, y: 155, width: 240, height: 240), items: [
    PNPieChartDataItem(value: 20, color: .red, description: "Item 1"),
    PNPieChartDataItem(value: 30, color: .blue, description: "Item 2"),
    PNPieChartDataItem(value: 50, color: .green, description: "Item 3")
])
pieChart.descriptionTextColor = .white
pieChart.descriptionTextFont = UIFont(name: "Avenir-Medium", size: 11)!
pieChart.strokeChart()

self.view.addSubview(pieChart)

Getting Started

  1. Add PNChart to your project using CocoaPods:

    pod 'PNChart'
    
  2. Import PNChart in your Swift file:

    import PNChart
    
  3. Create and customize a chart (e.g., line chart):

    let lineChart = PNLineChart(frame: CGRect(x: 0, y: 0, width: 320, height: 200))
    lineChart.yLabelFormat = "%1.1f"
    lineChart.xLabels = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN"]
    lineChart.yValues = [30.0, 20.0, 50.0, 40.0, 70.0, 90.0]
    lineChart.strokeChart()
    self.view.addSubview(lineChart)
    

Competitor Comparisons

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

Pros of MPAndroidChart

  • More comprehensive and feature-rich, offering a wider variety of chart types
  • Better documentation and community support
  • Actively maintained with frequent updates

Cons of MPAndroidChart

  • Steeper learning curve due to its extensive feature set
  • Larger library size, which may impact app size

Code Comparison

PNChart (iOS, Objective-C):

PNBarChart *barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 135, SCREEN_WIDTH, 200)];
barChart.yLabelFormatter = ^(CGFloat yValue){
    return [NSString stringWithFormat:@"%.1f",yValue];
};
[barChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5"]];
[barChart setYValues:@[@1,  @10, @2, @6, @3]];
[barChart strokeChart];

MPAndroidChart (Android, Java):

BarChart barChart = findViewById(R.id.barChart);
ArrayList<BarEntry> entries = new ArrayList<>();
entries.add(new BarEntry(0f, 1));
entries.add(new BarEntry(1f, 10));
entries.add(new BarEntry(2f, 2));
entries.add(new BarEntry(3f, 6));
entries.add(new BarEntry(4f, 3));
BarDataSet dataSet = new BarDataSet(entries, "Data Set");
BarData data = new BarData(dataSet);
barChart.setData(data);
barChart.invalidate();

📈📊🚀🚀🚀An elegant modern declarative data visualization chart framework for iOS, iPadOS and macOS. Extremely powerful, supports line, spline, area, areaspline, column, bar, pie, scatter, angular gauges, arearange, areasplinerange, columnrange, bubble, box plot, error bars, funnel, waterfall and polar chart types. 极其精美而又强大的现代化声明式数据可视化图表框架,支持柱状图、条形图、折线图、曲线图、折线填充图、曲线填充图、气泡图、扇形图、环形图、散点图、雷达图、混合图等各种类型的多达几十种的信息图图表,完全满足工作所需.

Pros of AAChartKit

  • More comprehensive and feature-rich charting library
  • Supports a wider variety of chart types and customization options
  • Active development and frequent updates

Cons of AAChartKit

  • Steeper learning curve due to more complex API
  • Larger file size and potential performance impact for simpler projects

Code Comparison

PNChart:

let lineChart = PNLineChart(frame: CGRect(x: 0, y: 135, width: 320, height: 200))
lineChart.yLabelFormat = "%1.1f"
lineChart.xLabels = ["SEP 1","SEP 2","SEP 3","SEP 4","SEP 5"]
lineChart.strokeChart()

AAChartKit:

let aaChartModel = AAChartModel()
    .chartType(.line)
    .title("Line Chart")
    .categories(["SEP 1", "SEP 2", "SEP 3", "SEP 4", "SEP 5"])
    .series([
        AASeriesElement()
            .name("Tokyo")
            .data([7.0, 6.9, 9.5, 14.5, 18.2])
    ])

Both libraries offer easy-to-use APIs for creating charts, but AAChartKit provides more detailed configuration options and a wider range of chart types. PNChart has a simpler API, making it easier to get started with basic charts, while AAChartKit offers more advanced features for complex visualizations.

Android Graph Library for creating zoomable and scrollable line and bar graphs.

Pros of GraphView

  • More comprehensive documentation and examples
  • Supports a wider variety of graph types (line, bar, point, combined)
  • Active development with regular updates and bug fixes

Cons of GraphView

  • Steeper learning curve due to more complex API
  • Larger library size, which may impact app performance
  • Less visually appealing default styling compared to PNChart

Code Comparison

PNChart (Swift):

let lineChart = PNLineChart(frame: CGRect(x: 0, y: 135, width: 320, height: 200))
lineChart.yLabelFormat = "%1.1f"
lineChart.xLabels = ["SEP 1","SEP 2","SEP 3","SEP 4","SEP 5"]
lineChart.yValues = [dataItem1,dataItem2,dataItem3,dataItem4,dataItem5]
lineChart.strokeChart()

GraphView (Java):

GraphView graph = new GraphView(this);
LineGraphSeries<DataPoint> series = new LineGraphSeries<>(new DataPoint[] {
    new DataPoint(0, 1),
    new DataPoint(1, 5),
    new DataPoint(2, 3),
    new DataPoint(3, 2),
    new DataPoint(4, 6)
});
graph.addSeries(series);

Both libraries offer easy-to-use APIs for creating charts, but GraphView provides more flexibility and customization options at the cost of increased complexity. PNChart focuses on simplicity and aesthetics, making it ideal for quick implementations, while GraphView is better suited for more advanced charting needs.

Interactive plotting library for .NET

Pros of ScottPlot

  • Cross-platform support for .NET, including WinForms, WPF, Avalonia, and more
  • Extensive documentation and examples
  • Active development and community support

Cons of ScottPlot

  • Steeper learning curve for beginners
  • Limited built-in chart types compared to PNChart

Code Comparison

PNChart (Objective-C):

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"]];
[lineChart setYValues:@[@1, @10, @2, @6, @3]];
[lineChart strokeChart];

ScottPlot (C#):

var plt = new ScottPlot.Plot(600, 400);
double[] xs = { 1, 2, 3, 4, 5 };
double[] ys = { 1, 10, 2, 6, 3 };
plt.AddScatter(xs, ys);
plt.SaveFig("lineplot.png");

ScottPlot offers more flexibility and customization options, while PNChart provides a simpler API for basic chart creation. ScottPlot's cross-platform nature makes it suitable for a wider range of applications, but PNChart's focus on iOS development may be preferable for specific mobile projects.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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