1. #import "ViewController.h"
  2.  
  3. @interface ViewController ()
  4. //要绘制基于x,y轴的图形
  5. @property(nonatomic,retain)CPTXYGraph *graph;
  6. @property(nonatomic,retain)NSMutableArray *dataForPlot;
  7. //要绘制的view 必须为CPTGraphicView
  8. @property(nonatomic,assign)CPTGraphHostingView *hostview;
  9. @end
  10.  
  11. @implementation ViewController
  12.  
  13. - (void)viewDidLoad
  14. {
  15. [super viewDidLoad];
  16. // Do any additional setup after loading the view, typically from a nib.
  17. [self LoadInit];
  18. [self SetUpCoreplotViews];
  19. }
  20.  
  21. -(void)LoadInit{
  22. self.hostview=[[[CPTGraphHostingView alloc] initWithFrame:CGRectMake(, , , )] autorelease];
  23.  
  24. self.dataForPlot=[NSMutableArray array];
  25. [self.view addSubview:_hostview];
  26.  
  27. }
  28.  
  29. -(void)SetUpCoreplotViews{
  30.  
  31. //1:创建线性
  32. CPTMutableLineStyle *lineStyle=[CPTMutableLineStyle lineStyle];
  33. //基于x,y轴图形的画布
  34. self.graph=[[[CPTXYGraph alloc] initWithFrame:CGRectZero] autorelease];
  35. //设置主题
  36. CPTTheme *them=[CPTTheme themeNamed:kCPTStocksTheme];
  37. //把主题设置到画布上
  38. [self.graph applyTheme:them];
  39.  
  40. //设置画布距离view的边距
  41. self.graph.paddingLeft=10.0f;
  42. self.graph.paddingTop=10.0f;
  43. self.graph.paddingRight=10.0f;
  44. self.graph.paddingBottom=10.0f;
  45. //然后把画布设置到指定view上
  46. self.hostview.hostedGraph=_graph;
  47.  
  48. //设置画布在屏幕类可显示的x,y刻度
  49. CPTXYPlotSpace *plotSpace=(CPTXYPlotSpace *)_graph.defaultPlotSpace;
  50. //可以移动
  51. plotSpace.allowsUserInteraction=YES;
  52. plotSpace.xRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromCGFloat(1.0) length:CPTDecimalFromCGFloat(2.0)];
  53. plotSpace.yRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromCGFloat(1.0) length:CPTDecimalFromCGFloat(3.0)];
  54.  
  55. //axes 设置x,y轴属性,如原点。
  56. //得到x,y轴的集合
  57. CPTXYAxisSet *axisSet=(CPTXYAxisSet *)self.graph.axisSet;
  58. lineStyle.miterLimit=1.0f;
  59. lineStyle.lineWidth=2.0f;
  60. lineStyle.lineColor=[CPTColor whiteColor];
  61.  
  62. CPTXYAxis *x=axisSet.xAxis;
  63. x.orthogonalCoordinateDecimal=CPTDecimalFromString(@"");//原点为3.(y=3)
  64. x.majorIntervalLength=CPTDecimalFromString(@"0.5");//主刻度之间检举
  65. x.minorTicksPerInterval=;//主刻度中显示的细分刻度的数目
  66. x.minorTickLineStyle=lineStyle;
  67. //需要排除的不显示数字的主刻度
  68.  
  69. NSArray *exclusionRange=[NSArray arrayWithObjects:[self CPTPlotRangeFromFloat:0.99 length:0.02],[self CPTPlotRangeFromFloat:2.99 length:0.02],nil];
  70. x.labelExclusionRanges=exclusionRange;
  71.  
  72. //设置y 轴
  73. CPTXYAxis *y=axisSet.yAxis;
  74. y.orthogonalCoordinateDecimal=CPTDecimalFromString(@"");
  75. y.majorIntervalLength=CPTDecimalFromString(@"0.5");
  76. y.minorTicksPerInterval=;
  77. y.minorTickLineStyle=lineStyle;
  78.  
  79. NSArray *yexclusionRange=[NSArray arrayWithObjects:[self CPTPlotRangeFromFloat:0.99 length:0.22],[self CPTPlotRangeFromFloat:2.99 length:0.22],nil];
  80. y.labelExclusionRanges=yexclusionRange;
  81.  
  82. }
  83.  
  84. -(CPTPlotRange *)CPTPlotRangeFromFloat:(float)location length:(float)length
  85. {
  86. return [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(location) length:CPTDecimalFromFloat(length)];
  87. }
  88.  
  89. - (void)dealloc
  90. {
  91. [_graph release];
  92. [_dataForPlot release];
  93. [super dealloc];
  94. }

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

画折线

  1. //
  2. // ViewController.m
  3. // corePlot
  4. //
  5. // Created by ganchaobo on 13-7-31.
  6. // Copyright (c) 2013年 ganchaobo. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10.  
  11. @interface ViewController ()
  12. //要绘制基于x,y轴的图形
  13. @property(nonatomic,retain)CPTXYGraph *graph;
  14. @property(nonatomic,retain)NSMutableArray *dataForPlot;
  15. //要绘制的view 必须为CPTGraphicView
  16. @property(nonatomic,assign)CPTGraphHostingView *hostview;
  17. @end
  18.  
  19. @implementation ViewController
  20.  
  21. - (void)viewDidLoad
  22. {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view, typically from a nib.
  25. [self LoadInit];
  26. [self SetUpCoreplotViews];
  27. }
  28.  
  29. -(void)LoadInit{
  30. self.hostview=[[[CPTGraphHostingView alloc] initWithFrame:CGRectMake(, , , )] autorelease];
  31.  
  32. self.dataForPlot=[NSMutableArray array];
  33. [self.view addSubview:_hostview];
  34. //_dataForPlot = [NSMutableArray arrayWithCapacity:100];
  35. NSUInteger i;
  36. for ( i = ; i < ; i++ ) {
  37. id x = [NSNumber numberWithFloat: + i * 0.05];
  38. id y = [NSNumber numberWithFloat:1.2 * rand() / (float)RAND_MAX + 1.2];
  39. [_dataForPlot addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]];
  40. }
  41.  
  42. }
  43.  
  44. -(void)SetUpCoreplotViews{
  45.  
  46. //1:创建线性
  47. CPTMutableLineStyle *lineStyle=[CPTMutableLineStyle lineStyle];
  48. //基于x,y轴图形的画布
  49. self.graph=[[[CPTXYGraph alloc] initWithFrame:CGRectZero] autorelease];
  50. //设置主题
  51. CPTTheme *them=[CPTTheme themeNamed:kCPTStocksTheme];
  52. //把主题设置到画布上
  53. [self.graph applyTheme:them];
  54.  
  55. //设置画布距离view的边距
  56. self.graph.paddingLeft=10.0f;
  57. self.graph.paddingTop=10.0f;
  58. self.graph.paddingRight=10.0f;
  59. self.graph.paddingBottom=10.0f;
  60. //然后把画布设置到指定view上
  61. self.hostview.hostedGraph=_graph;
  62.  
  63. //设置画布在屏幕类可显示的x,y刻度
  64. CPTXYPlotSpace *plotSpace=(CPTXYPlotSpace *)_graph.defaultPlotSpace;
  65. //可以移动
  66. plotSpace.allowsUserInteraction=YES;
  67. plotSpace.xRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromCGFloat(1.0) length:CPTDecimalFromCGFloat(2.0)];
  68. plotSpace.yRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromCGFloat(1.0) length:CPTDecimalFromCGFloat(3.0)];
  69.  
  70. //axes 设置x,y轴属性,如原点。
  71. //得到x,y轴的集合
  72. CPTXYAxisSet *axisSet=(CPTXYAxisSet *)self.graph.axisSet;
  73. lineStyle.miterLimit=1.0f;
  74. lineStyle.lineWidth=2.0f;
  75. lineStyle.lineColor=[CPTColor whiteColor];
  76.  
  77. CPTXYAxis *x=axisSet.xAxis;
  78. x.orthogonalCoordinateDecimal=CPTDecimalFromString(@"");//原点为3.(y=3)
  79. x.majorIntervalLength=CPTDecimalFromString(@"0.5");//主刻度之间检举
  80. x.minorTicksPerInterval=;//主刻度中显示的细分刻度的数目
  81. x.minorTickLineStyle=lineStyle;
  82. //需要排除的不显示数字的主刻度
  83.  
  84. NSArray *exclusionRange=[NSArray arrayWithObjects:[self CPTPlotRangeFromFloat:0.99 length:0.02],[self CPTPlotRangeFromFloat:2.99 length:0.02],nil];
  85. x.labelExclusionRanges=exclusionRange;
  86.  
  87. //设置y 轴
  88. CPTXYAxis *y=axisSet.yAxis;
  89. y.orthogonalCoordinateDecimal=CPTDecimalFromString(@"");
  90. y.majorIntervalLength=CPTDecimalFromString(@"0.5");
  91. y.minorTicksPerInterval=;
  92. y.minorTickLineStyle=lineStyle;
  93.  
  94. NSArray *yexclusionRange=[NSArray arrayWithObjects:[self CPTPlotRangeFromFloat:0.99 length:0.22],[self CPTPlotRangeFromFloat:2.99 length:0.22],nil];
  95. y.labelExclusionRanges=yexclusionRange;
  96.  
  97. //画折线
  98. lineStyle.miterLimit=1.0f;
  99. lineStyle.lineWidth=3.0f;
  100. lineStyle.lineColor=[CPTColor blueColor];
  101.  
  102. //折线的对象
  103. CPTScatterPlot *boundlinePlot=[[CPTScatterPlot alloc] init];
  104. boundlinePlot.dataLineStyle=lineStyle;
  105. boundlinePlot.identifier=@"blue";
  106. boundlinePlot.dataSource=self;
  107.  
  108. [_graph addPlot:boundlinePlot];
  109.  
  110. }
  111.  
  112. -(CPTPlotRange *)CPTPlotRangeFromFloat:(float)location length:(float)length
  113. {
  114. return [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(location) length:CPTDecimalFromFloat(length)];
  115. }
  116.  
  117. #pragma mark -plot delegate
  118. -(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot{
  119. return self.dataForPlot.count;
  120. }
  121.  
  122. -(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
  123. {
  124. NSString * key = (fieldEnum == CPTScatterPlotFieldX ? @"x" : @"y");
  125. NSNumber * num = [[_dataForPlot objectAtIndex:index] valueForKey:key];
  126.  
  127. NSLog(@"%zi-->%@",[num intValue],key);
  128.  
  129. return num;
  130. }
  131.  
  132. - (void)dealloc
  133. {
  134. [_graph release];
  135. [_dataForPlot release];
  136. [super dealloc];
  137. }
  138. @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. libnids使用举例

    ---[[ libnids应用实例 ]]---------------------------------- 1.nids_next()函数的应用 ========================== ...

  2. Remote Desktop Session中如何触发Ctrl+Alt+Delete?

    Ctrl+Alt+End is a keyboard shortcut used in a Remote Desktop Session to display the security dialog ...

  3. C#利用tabControl控件实现多窗体嵌入及关闭

    创建一个主窗体(Formmain).两个副窗体(Form1,Form2);在主窗体中分别添加一个menuStrip控件.tabControl控件,并在menu控件上添加一个主菜单和两个子菜单   继而 ...

  4. 【Python】无须numpy,利用map函数与zip(*)函数对数组转置(转)

    http://blog.csdn.net/yongh701/article/details/50283689 在Python的numpy中,对类似array=[[1,2,3],[4,5,6],[7,8 ...

  5. python 听课笔记(一)

  6. 安装loadrunner

    Loadrunner安装具体解释 一 .下载篇. 我的下载地址是:http://pan.baidu.com/s/1c0IqAOC 程序4G多.非常大. 二.           安装篇 1.执行&qu ...

  7. vSCode打开文件老覆盖原窗口

    https://segmentfault.com/q/1010000006131199?_ea=1023522 设置中搜preview,改为false

  8. LintCode: Search A 2d Matrix

    1. 设查找的数位y,第一行最后一列的数位x 如果x<y,x是第一行最大的,所以第一行都小于y,删除第一行: 如果x>y,x是最后一列最小的,所以最后一列都大于y,删除最后一列: 这样保证 ...

  9. Jenkins知识地图

    转自:http://blog.csdn.net/feiniao1221/article/details/10259449 这篇文章大概写于三个月前,当时写了个大纲列表,但是在CSDN上传资源实在不方便 ...

  10. python转换html到pdf文件

    1.安装wkhtmltopdf Windows平台直接在 http://wkhtmltopdf.org/downloads.html 下载稳定版的 wkhtmltopdf 进行安装,安装完成之后把该程 ...