CorePlot学习 点击scatterPlot中的symbol点时弹出相应的注释

首先要引用委托方法:CPTScatterPlotDelegate、CPTPlotSpaceDelegate

完成如下:

#pragma mark -
#pragma mark CPTPlotSpaceDelegate methods
-(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceCancelledEvent:(UIEvent *)event
{
    return YES;
}
-(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceUpEvent:(UIEvent *)event atPoint:(CGPoint)point
{
    return YES;
}
-(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceDownEvent:(UIEvent *)event atPoint:(CGPoint)point
{
    NSLog(@"you putdown at point:%@",[NSValue valueWithCGPoint:point]
);
    return YES;
}
-(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceDraggedEvent:(UIEvent *)event atPoint:(CGPoint)point
{
    return YES;
}  

#pragma mark -
#pragma mark CPTScatterPlotDelegate
//当我们选择相应的点时,弹出注释:
-(void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)idx withEvent:(UIEvent *)event
{  

    if ( symbolTextAnnotation ) {
        [xyGraph.plotAreaFrame.plotArea removeAnnotation:symbolTextAnnotation];
        symbolTextAnnotation = nil;
    }
    // Setup a style for the annotation
    CPTMutableTextStyle *hitAnnotationTextStyle = [CPTMutableTextStyle textStyle];
    hitAnnotationTextStyle.color    = [CPTColor greenColor];
    hitAnnotationTextStyle.fontSize = 10.0f;
    hitAnnotationTextStyle.fontName = @"Helvetica-Bold";  

    // Determine point of symbol in plot coordinates
    NSNumber *x          =
    [[datasForPlot objectAtIndex:idx] valueForKey:@"x"];
    NSNumber *y          = [[datasForPlot objectAtIndex:idx] valueForKey:@"y"];
    NSString *date = [[datasForPlot objectAtIndex:idx]valueForKey:@"date"];  

    NSArray *anchorPoint = [NSArray arrayWithObjects:x, y, nil nil];
    // Add annotation
    // First make a string for the y value
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    [formatter setMaximumFractionDigits:2];
    NSString *yString = [formatter stringFromNumber:y];
    NSString *myString = [NSString stringWithFormat:@"温度:%@\n日期:%@\n事件:%@",yString,date,nil];  

    // Now add the annotation to the plot area
    CPTTextLayer *textLayer = [[CPTTextLayer alloc] initWithText:myString/*yString*/ style:hitAnnotationTextStyle];
    symbolTextAnnotation              = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:xyGraph.defaultPlotSpace anchorPlotPoint:anchorPoint];
    symbolTextAnnotation.contentLayer = textLayer;
    symbolTextAnnotation.displacement = CGPointMake(0.0, 20.0);
    [xyGraph.plotAreaFrame.plotArea addAnnotation:symbolTextAnnotation];  

   // NSLog(@"index:%lu,event:%@",(unsigned long)idx,event);
}  

千万别忘记了根据自己定义的设置相应的delegate = self;

红色标注的就是我们实现该功能的重点

对了,忘记说一点,该点非常重要,不然你手指点击不灵活。我们的symbol那么小,还要点击到它的中心才能触发下面的方法,这多难啊,有个参数设置一下就搞定了,设置它的触发范围:

    CPTScatterPlot *boundLinePlot = [[CPTScatterPlot alloc]init];
    boundLinePlot.plotSymbolMarginForHitDetection = 5.0f;//设置symbol点的外沿范围,以用来检测手指的触摸  
时间: 2024-08-03 22:33:12

CorePlot学习 点击scatterPlot中的symbol点时弹出相应的注释的相关文章

CorePlot学习六---点击scatterPlot中的symbol点时弹出相应的注释

由于项目需要用到用户点击 symbol时,弹出相应的详细信息,发现国内讲解的比较少,经过一番搜索验证终于解决,先看效果图: 具体需要修改的代码如下: 首先要引用委托方法:CPTScatterPlotDelegate.CPTPlotSpaceDelegate 完成如下: #pragma mark - #pragma mark CPTPlotSpaceDelegate methods -(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointin

CorePlot学习六---点击scatterPlot中的symbol点时弹出对应的凝视

因为项目须要用到用户点击 symbol时,弹出对应的具体信息,发现国内解说的比較少,经过一番搜索验证最终解决,先看效果图: 详细须要改动的代码例如以下: 首先要引用托付方法:CPTScatterPlotDelegate.CPTPlotSpaceDelegate 完毕例如以下: #pragma mark - #pragma mark CPTPlotSpaceDelegate methods -(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePoi

解决Windows Server2008 R2中IE开网页时弹出阻止框

使用Windows Server2008,用IE打开网站时会弹出"Internet Explorer增强安全配置正在阻止来自下列网站的此应用程序中的内容"的对话框.如下图所示: 2011-10-14_205047-300x243 禁止弹出此类对话框的步骤: 1 打开服务器管理器,在"安全信息"栏的右侧点击"配置IE ESC" 2011-10-14_204750-300x150 2 在弹出的对话框中将"管理员"和"用户

EBS OAF开发中实现參数式弹出窗体

(版权声明,本人原创或者翻译的文章如需转载,如转载用于个人学习,请注明出处:否则请与本人联系,违者必究) 概览 參数式弹出窗体和嵌入式弹出窗体不一样,它拥有独立的区域,并不嵌入到使用页面中,它里面的内容依据须要来获取和生成,它拥有自己的AM和页面状态,对popup页面事件的处理也不一样.两种弹出式窗体都仅仅在以下四种组件所支持,既不能改变大小也不可移动. 1.        Text(messageStyledText) 2.        Image 3.        Link 4.    

android的alertdialog中加入edittext但是不弹出软键盘等问题的解决与原因

摘要:alertdialog中加入edittext但是不弹出软键盘等问题网上有很多不管用的解决方案, 本文意在给出更有效的解决办法,并初步探究其原因 正文 在对话框中插入文本框是十分常见的需求 通常我们选择在代码中创建edittext对象 这个时候就需要在代码中给edittext设置输入属性了 但是经常发现设置的属性不起作用,甚至都不弹出软键盘(虽然实体键盘可以输入) 问题的解决方案有很多种,这里介绍一种我比较常用的方法: inputPassEditText.setInputType(Input

点击删除时弹出是否删除提示框

点击删除时弹出是否删除提示框:在通常情况下,想要点击删除某一项的时候,一般会弹出一个框,以提示操作者是否真的要删除此项,这样可以免于出现误操作,比较人性化的一个举措,下面就简单介绍一下如何实现此效果.实例代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.soft

Android点击返回键back时弹出对话框Dialog

public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { ExitDialog(MainActivity.this).show(); return true; } return super.onKeyDown(keyCode, event); } private Dialog ExitDialog

dedecms(织梦)在后台新建新的模型时 ,点击编辑的时候 更新时间不能弹出

dedecms(织梦)在后台新建新的模型时 ,点击编辑的时候 更新时间不能弹出 ,分析了一下代码发现htm文件少了个js代码,其实很简单,我想dede官方也不会想到自己会写错. 解决办法 后台栏目默认是dede 那么就是/dede/templates/archives_edit.htm <td width="250"><?php $nowtime = GetDateTimeMk(time()); echo "<input name=\"pub

VS2015+OpenGL4.0开发编译时弹出错误:glaux.lib(tk.obj) : error LNK2019: 无法解析的外部符号 _sscanf,该符号在函数 [email&#160;protected] 中被引用

一.问题描述: VS2015+OpenGL4.0开发编译时弹出如下所示的错误: 1>glaux.lib(tk.obj) : error LNK2019: 无法解析的外部符号 _sscanf,该符号在函数 [email protected] 中被引用 1>glaux.lib(tk.obj) : error LNK2019: 无法解析的外部符号 _vsprintf,该符号在函数 _PrintMessage 中被引用 二.问题原因: VS2015默认编译时将许多标准库采用内联方式处理,因而没有可以链