• ios中core Plot (2)


    #import "ViewController.h"
    
    @interface ViewController ()
    //指定要画得view
    @property(nonatomic,assign)CPTGraphHostingView *hostview;
    //指定画布
    @property(nonatomic,retain)CPTXYGraph *graph;
    
    @property(nonatomic,retain)NSMutableArray *data;
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        self.data=[NSMutableArray array];
        for (int i=0; i<50; i++) {
            
            id x=[NSNumber numberWithInt:i];
            id y=[NSNumber numberWithInt:(i+0.11)];
            [self.data addObject:@{@"x":x,@"y":y}];
        }
        self.hostview=[[CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
        
        //创建x,Y轴画布
        self.graph=[[[CPTXYGraph alloc] initWithFrame:CGRectZero] autorelease];
        //设置主题
        CPTTheme *them=[CPTTheme themeNamed:kCPTStocksTheme];
        //设置x.y周画布的主题
        [self.graph applyTheme:them];
        
        self.graph.paddingBottom=0.0f;
        self.graph.paddingLeft=0.0f;
        self.graph.paddingRight=0.0f;
        self.graph.paddingTop=0.0f;
        self.hostview.hostedGraph=self.graph;
        [self.view addSubview:self.hostview];
        
        
        CPTMutableLineStyle *linestyle=[CPTMutableLineStyle lineStyle];
        linestyle.lineWidth=3.0f;
        linestyle.lineColor=[CPTColor redColor];
        linestyle.miterLimit=1.0f;
        
        CPTScatterPlot *scatter=[[CPTScatterPlot alloc] init];
        scatter.dataLineStyle=linestyle;
        scatter.dataSource=self;
        scatter.identifier=@"red";
        [self.graph addPlot:scatter];
        
    }
    
    
    -(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot;{
        return  self.data.count;
    }
    
    
    -(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index{
        NSString *key= (fieldEnum==CPTScatterPlotFieldX?@"x":@"y");
        NSDictionary *dic=self.data[index];
        NSLog(@"%@--->%@",key,dic[key]);
        return dic[key];
        
        
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    - (void)dealloc
    {
        [_graph release];
        [super dealloc];
    }
    
    @end
  • 相关阅读:
    Hibernate4与Spring3的不兼容问题
    关于Struts2框架下jsp获取action的布尔值问题
    js 操作select和option常见用法
    用socaket编写客户端与服务端程序相互发送消息
    Web编程
    第二篇
    java基础
    GeoServer style标注中文乱码配置
    RabbitMQ高可用方案总结
    Visual Studio 2019 注册KEY
  • 原文地址:https://www.cnblogs.com/gcb999/p/3229871.html
Copyright © 2020-2023  润新知