上海快风信息科技有限公司程序员iOS开发资料收集区

iOS一款简单的图表库-FSChartView

2018-02-06  本文已影响69人  Fly_Sunshine_J

Introduction

FSChartView一款简单的图表库,内含柱状图(垂直&水平)、折线图、饼状图。
柱状图是使用UICollectionView实现,因为UICollectionView自带缓存池,所以选择UICollectionView,里面的很多delegate方法和dataSource方法,看起来很熟悉。折线图和饼状图主要使用CAShapeLayer和UIBezierPath实现。(柱状图写的是最low的,折线图写的是最bad的)

Overview

垂直柱状图.gif 水平柱状图.gif 折线图.gif 饼状图.gif 支持StoryBoard.gif

Using CocoaPods

target 'projectName' do
use_frameworks!
pod 'FSChartView', '~> 1.0.0'
end

Tip

如果不能search到,请更新cocoapods库 , pod setup 如果还搜索不到,删除~/Library/Caches/CocoaPods目录下的search_index.json文件 再search

List

目录.png

Usage

三种图表的用法都必须遵守dataSource代理,实现对应必须要实现的dataSource方法。用法基本上都很统一,初始化之后设置dataSource和delgate,然后实现该实现的方法就可以。支持StoryBoard。

柱状图

垂直柱状图.png
水平柱状图.png
垂直柱状图
    FSBarChartView *chartView = [[FSBarChartView alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 200)];
    self.chartView = chartView;
    [self.chartView registerClass:[FSBarChartViewCell class] forCellWithReuseIdentifier:@"CELL"];
    chartView.delegate = self;
    chartView.dataSource = self;
    [self.view addSubview:chartView];
    self.chartView.abscissaAxis.backgroundColor = [UIColor greenColor];

水平柱状图
    FSBarChartView *chartView = [[FSBarChartView alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 200) orientation:FSBarChartViewOrientationHorizontal];
    self.chartView = chartView;
    [self.chartView registerClass:[FSBarChartViewCell class] forCellWithReuseIdentifier:@"CELL"];
    chartView.delegate = self;
    chartView.dataSource = self;
    [self.view addSubview:chartView];

Note:

折线图

折线图.png
   FSLineChartView *lineViewChart = [[FSLineChartView alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 200)];
   self.lineChartView  = lineViewChart;
   lineViewChart.delegate = self;
   lineViewChart.dataSource = self;
   [self.view addSubview:lineViewChart];

Note:

饼状图

饼状图.png
  FSPieChartView *pieChartView = [[FSPieChartView alloc] initWithFrame:CGRectMake(0, self.navigationController.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height + 20, self.view.frame.size.width, height)];
  pieChartView.delegate = self;
  pieChartView.dataSource = self;
  [self.view addSubview:pieChartView];
  self.chartView = pieChartView;

Note:

总结

虽然自己感觉写的不怎么样,但是也算给自己的一种鼓励。如果你喜欢欢迎在Github上star。如果有什么问题,欢迎各位留言。

上一篇 下一篇

猜你喜欢

热点阅读