关于Core-Plot的配置,大家可以参考我的上一篇博客:
版权所有,转载请注明原文转自:
大家可以到:观看本篇博客更友好的排版格式
或者你英语好也可以参考github上的wiki介绍:
先看一下效果图:
好了下面说说具体使用吧:
1.修改ViewController.h文件如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
//
// ViewController.h
// CorePlotDemo
// Created by wildcat on 14-5-9.
// Copyright (c) 2014年 com.wildcat. All rights reserved.
#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"
@interface ViewController : UIViewController<CPTPlotDataSource>
@property (nonatomic, strong) CPTGraphHostingView *hostView;
@end
2.在.m文件中的implement下面添加
@synthesizehostView=hostView_;
3.在下面接着添加几个方法
14
15
16
17
18
19
20
21
22
23
24
25
#pragma mark - UIViewController lifecycle methods
-(void)viewDidAppear:(BOOL)animated
{
[super
viewDidAppear:animated];
[self
initPlot];
}
#pragma mark - Chart behavior
-(void)initPlot
configureHost];
configureGraph];
configurePlots];
configureAxes];
-(void)configureHost
{
-(void)configureGraph
-(void)configurePlots
-(void)configureAxes
4.在@end上边添加
5.添加下面代码到-(void)configureHost函数:
以上代码的主要作用就是声明一个视图用于绘图,下面的折线图将绘制到这个视图上,然后添加为self.view的子视图。
6.添加下面代码到configureGraph:
7.添加下面代码到configurePlots:
以上代码主要是设置折线、拐点的类型以及设置高低温两个折线图.最重要的是添加数据源 .dataSource = self;
8.设置x、y轴的间隔及细分刻度等,添加以下代码到configureAxes函数:
9.设置数据源方法,修改两个方法如下:
好了一切设置完毕运行看看效果。
CorePlot 的类结构关系如下:
其中最核心的就是 CPTGraph,本示例中的 CPTXYGraph是它的子类;一个图 CPTGraph包含一个轴集 CPTAxiset,每个轴集可包含多个轴;一个图 CPTGraph 可包含多个图空间 CPTPlotSpace;一个图 CPTGraph 可包含多个图形CPTSplot(曲线,饼图,柱状图等);图形CPTSplot 和轴都展现在某个图空间 CPTPlotSpace 中。其余的部分,尚未介绍到,暂且不提。
也许下图能更形象地描述出 Core Plot 各种对象之间的关系。