#import "ViewController.h"

@interface ViewController ()
//要绘制基于x,y轴的图形
@property(nonatomic,retain)CPTXYGraph *graph;
@property(nonatomic,retain)NSMutableArray *dataForPlot;
//要绘制的view 必须为CPTGraphicView
@property(nonatomic,assign)CPTGraphHostingView *hostview;
@end @implementation ViewController - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self LoadInit];
[self SetUpCoreplotViews];
} -(void)LoadInit{
self.hostview=[[[CPTGraphHostingView alloc] initWithFrame:CGRectMake(, , , )] autorelease]; self.dataForPlot=[NSMutableArray array];
[self.view addSubview:_hostview]; } -(void)SetUpCoreplotViews{ //1:创建线性
CPTMutableLineStyle *lineStyle=[CPTMutableLineStyle lineStyle];
//基于x,y轴图形的画布
self.graph=[[[CPTXYGraph alloc] initWithFrame:CGRectZero] autorelease];
//设置主题
CPTTheme *them=[CPTTheme themeNamed:kCPTStocksTheme];
//把主题设置到画布上
[self.graph applyTheme:them]; //设置画布距离view的边距
self.graph.paddingLeft=10.0f;
self.graph.paddingTop=10.0f;
self.graph.paddingRight=10.0f;
self.graph.paddingBottom=10.0f;
//然后把画布设置到指定view上
self.hostview.hostedGraph=_graph; //设置画布在屏幕类可显示的x,y刻度
CPTXYPlotSpace *plotSpace=(CPTXYPlotSpace *)_graph.defaultPlotSpace;
//可以移动
plotSpace.allowsUserInteraction=YES;
plotSpace.xRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromCGFloat(1.0) length:CPTDecimalFromCGFloat(2.0)];
plotSpace.yRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromCGFloat(1.0) length:CPTDecimalFromCGFloat(3.0)]; //axes 设置x,y轴属性,如原点。
//得到x,y轴的集合
CPTXYAxisSet *axisSet=(CPTXYAxisSet *)self.graph.axisSet;
lineStyle.miterLimit=1.0f;
lineStyle.lineWidth=2.0f;
lineStyle.lineColor=[CPTColor whiteColor]; CPTXYAxis *x=axisSet.xAxis;
x.orthogonalCoordinateDecimal=CPTDecimalFromString(@"");//原点为3.(y=3)
x.majorIntervalLength=CPTDecimalFromString(@"0.5");//主刻度之间检举
x.minorTicksPerInterval=;//主刻度中显示的细分刻度的数目
x.minorTickLineStyle=lineStyle;
//需要排除的不显示数字的主刻度 NSArray *exclusionRange=[NSArray arrayWithObjects:[self CPTPlotRangeFromFloat:0.99 length:0.02],[self CPTPlotRangeFromFloat:2.99 length:0.02],nil];
x.labelExclusionRanges=exclusionRange; //设置y 轴
CPTXYAxis *y=axisSet.yAxis;
y.orthogonalCoordinateDecimal=CPTDecimalFromString(@"");
y.majorIntervalLength=CPTDecimalFromString(@"0.5");
y.minorTicksPerInterval=;
y.minorTickLineStyle=lineStyle; NSArray *yexclusionRange=[NSArray arrayWithObjects:[self CPTPlotRangeFromFloat:0.99 length:0.22],[self CPTPlotRangeFromFloat:2.99 length:0.22],nil];
y.labelExclusionRanges=yexclusionRange; } -(CPTPlotRange *)CPTPlotRangeFromFloat:(float)location length:(float)length
{
return [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(location) length:CPTDecimalFromFloat(length)];
} - (void)dealloc
{
[_graph release];
[_dataForPlot release];
[super dealloc];
}

参考文章 http://www.cnblogs.com/kesalin/archive/2013/04/04/coreplot_xygrapha.html

画折线

//
// ViewController.m
// corePlot
//
// Created by ganchaobo on 13-7-31.
// Copyright (c) 2013年 ganchaobo. All rights reserved.
// #import "ViewController.h" @interface ViewController ()
//要绘制基于x,y轴的图形
@property(nonatomic,retain)CPTXYGraph *graph;
@property(nonatomic,retain)NSMutableArray *dataForPlot;
//要绘制的view 必须为CPTGraphicView
@property(nonatomic,assign)CPTGraphHostingView *hostview;
@end @implementation ViewController - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self LoadInit];
[self SetUpCoreplotViews];
} -(void)LoadInit{
self.hostview=[[[CPTGraphHostingView alloc] initWithFrame:CGRectMake(, , , )] autorelease]; self.dataForPlot=[NSMutableArray array];
[self.view addSubview:_hostview];
//_dataForPlot = [NSMutableArray arrayWithCapacity:100];
NSUInteger i;
for ( i = ; i < ; i++ ) {
id x = [NSNumber numberWithFloat: + i * 0.05];
id y = [NSNumber numberWithFloat:1.2 * rand() / (float)RAND_MAX + 1.2];
[_dataForPlot addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]];
} } -(void)SetUpCoreplotViews{ //1:创建线性
CPTMutableLineStyle *lineStyle=[CPTMutableLineStyle lineStyle];
//基于x,y轴图形的画布
self.graph=[[[CPTXYGraph alloc] initWithFrame:CGRectZero] autorelease];
//设置主题
CPTTheme *them=[CPTTheme themeNamed:kCPTStocksTheme];
//把主题设置到画布上
[self.graph applyTheme:them]; //设置画布距离view的边距
self.graph.paddingLeft=10.0f;
self.graph.paddingTop=10.0f;
self.graph.paddingRight=10.0f;
self.graph.paddingBottom=10.0f;
//然后把画布设置到指定view上
self.hostview.hostedGraph=_graph; //设置画布在屏幕类可显示的x,y刻度
CPTXYPlotSpace *plotSpace=(CPTXYPlotSpace *)_graph.defaultPlotSpace;
//可以移动
plotSpace.allowsUserInteraction=YES;
plotSpace.xRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromCGFloat(1.0) length:CPTDecimalFromCGFloat(2.0)];
plotSpace.yRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromCGFloat(1.0) length:CPTDecimalFromCGFloat(3.0)]; //axes 设置x,y轴属性,如原点。
//得到x,y轴的集合
CPTXYAxisSet *axisSet=(CPTXYAxisSet *)self.graph.axisSet;
lineStyle.miterLimit=1.0f;
lineStyle.lineWidth=2.0f;
lineStyle.lineColor=[CPTColor whiteColor]; CPTXYAxis *x=axisSet.xAxis;
x.orthogonalCoordinateDecimal=CPTDecimalFromString(@"");//原点为3.(y=3)
x.majorIntervalLength=CPTDecimalFromString(@"0.5");//主刻度之间检举
x.minorTicksPerInterval=;//主刻度中显示的细分刻度的数目
x.minorTickLineStyle=lineStyle;
//需要排除的不显示数字的主刻度 NSArray *exclusionRange=[NSArray arrayWithObjects:[self CPTPlotRangeFromFloat:0.99 length:0.02],[self CPTPlotRangeFromFloat:2.99 length:0.02],nil];
x.labelExclusionRanges=exclusionRange; //设置y 轴
CPTXYAxis *y=axisSet.yAxis;
y.orthogonalCoordinateDecimal=CPTDecimalFromString(@"");
y.majorIntervalLength=CPTDecimalFromString(@"0.5");
y.minorTicksPerInterval=;
y.minorTickLineStyle=lineStyle; NSArray *yexclusionRange=[NSArray arrayWithObjects:[self CPTPlotRangeFromFloat:0.99 length:0.22],[self CPTPlotRangeFromFloat:2.99 length:0.22],nil];
y.labelExclusionRanges=yexclusionRange; //画折线
lineStyle.miterLimit=1.0f;
lineStyle.lineWidth=3.0f;
lineStyle.lineColor=[CPTColor blueColor]; //折线的对象
CPTScatterPlot *boundlinePlot=[[CPTScatterPlot alloc] init];
boundlinePlot.dataLineStyle=lineStyle;
boundlinePlot.identifier=@"blue";
boundlinePlot.dataSource=self; [_graph addPlot:boundlinePlot]; } -(CPTPlotRange *)CPTPlotRangeFromFloat:(float)location length:(float)length
{
return [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(location) length:CPTDecimalFromFloat(length)];
} #pragma mark -plot delegate
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot{
return self.dataForPlot.count;
} -(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
NSString * key = (fieldEnum == CPTScatterPlotFieldX ? @"x" : @"y");
NSNumber * num = [[_dataForPlot objectAtIndex:index] valueForKey:key]; NSLog(@"%zi-->%@",[num intValue],key); return num;
} - (void)dealloc
{
[_graph release];
[_dataForPlot release];
[super dealloc];
}
@end

ios core plot设置xy坐标的更多相关文章

  1. iOS 使用 Core Plot 绘制统计图表入门

     本文转载至 http://blog.csdn.net/zhibudefeng/article/details/7677457   iOS(iPhone/iPad) 下图形组件有两个有名的,s7gra ...

  2. 转 iOS Core Animation 动画 入门学习(一)基础

    iOS Core Animation 动画 入门学习(一)基础 reference:https://developer.apple.com/library/ios/documentation/Coco ...

  3. iOS Core Animation 简明系列教程

    iOS Core Animation 简明系列教程  看到无数的CA教程,都非常的难懂,各种事务各种图层关系看的人头大.自己就想用通俗的语言翻译给大家听,尽可能准确表达,如果哪里有问题,请您指出我会尽 ...

  4. iOS - Core Animation 核心动画

    1.UIView 动画 具体讲解见 iOS - UIView 动画 2.UIImageView 动画 具体讲解见 iOS - UIImageView 动画 3.CADisplayLink 定时器 具体 ...

  5. 如何使用 Core Plot 的 API 帮助文档

    Core Plot 可是 iOS 下绝好的图表组件,虽说它的相关资料不甚丰富,特别是中文的,英文的还是有几篇不错的文章,不过 Core Plot 自身提供的 API 帮助文档,以及代码示例其实很有用的 ...

  6. iOS开发UI篇—九宫格坐标计算

    iOS开发UI篇—九宫格坐标计算 一.要求 完成下面的布局 二.分析 寻找左边的规律,每一个uiview的x坐标和y坐标. 三.实现思路 (1)明确每一块用得是什么view (2)明确每个view之间 ...

  7. iOS开发--应用设置及用户默认设置【1、bundle的运用】

           在iphone里面,应用都会在“设置”里面有个专属的应用设置,选择该菜单界面,用户便可以在其中输入和更改各种选项,协助用户更便捷设置个人喜好与习惯. 在这一节中,希望能通过对捆绑包(bu ...

  8. iOS开发--应用设置及用户默认设置——转载

    [链接]iOS开发--应用设置及用户默认设置[1.bundlehttp://www.jianshu.com/p/6f2913f6b218 在iphone里面,应用都会在“设置”里面有个专属的应用设置, ...

  9. 解决iOS中 tabBarItem设置图片(image+title切图在一起)时造成的图片向上偏移

    解决iOS中 tabBarItem设置图片(image+title切图在一起)时造成的图片向上偏移 解决办法1:设置tabBarItem的imageInsets属性 代码示例: childContro ...

随机推荐

  1. MFC中位图的显示

    分析: 首先,我们要明确一点,窗口的绘制包括两个步骤,首先:擦除窗口背景,然后再对窗口重新进行绘制:当擦除窗口背景时,程序会发生一个WM_ERASEBKGND消息,因此可以在此响应函数中完成位图的显示 ...

  2. 关于APP接口设计 (转)

    转自:http://blog.csdn.net/gebitan505/article/details/37924711 1.效率:接口访问速度 PHP建议使用YAF框架. 最好使用JSON格式数据,因 ...

  3. Linux下逻辑地址-线性地址-物理地址图解(转)

    一.逻辑地址转线性地址 机器语言指令中出现的内存地址,都是逻辑地址,需要转换成线性地址,再经过MMU(CPU中的内存管理单元)转换成物理地址才能够被访问到. 我们写个最简单的hello world程序 ...

  4. Sql Server重复数据删除

    --在sql2005下可以 ,sql2000不可以 create  table tb(id int,name varchar(4))insert tb select 1,'aa'union all s ...

  5. logstash启动脚本

    1  nohup ./redis-server 1>log.log 2>error.log &  2 nohup ./elasticsearch -f & 3 nohup ...

  6. springboot项目中报错:listener does not currently know of SID given in connect descriptor

    springboot项目中报错:listener does not currently know of SID given in connect descriptor 出现这个问题的原因是SID写错了 ...

  7. 【转】application.properties 常见配置

    Various properties can be specified inside your application.properties/application.yml file or as co ...

  8. GetParam(name)

    function GetParam(name) { var match = new RegExp(name + "=*([^&]+)*", "i").e ...

  9. 关于extern "C"(详细剖析)

    [目录] 引言 extern “C”的前世今生 小心门后的未知世界 Q&A c++调用c的方法 c调用c++的方法 在你工作过的系统里,不知能否看到类似下面的代码. 这好像没有什么问题,你应该 ...

  10. Django模板过滤器详解

    Django 模板过滤器也是我们在以后基于 Django 网站开发过程中会经常遇到的,如显示格式的转换.判断处理等.以下是 Django 过滤器列表,希望对为大家的开发带来一些方便. 一.形式:小写 ...