zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    HDU5032 Always Cook Mushroom(树状数组&&离线)
    vue proxyTable
    vue-bus 组件通信插件
    gulp 静态资源版本控制
    js运算【按位非】~
    JS 的引用赋值与传值赋值
    手机端取消长按选中
    无刷新URL 更新
    移动端设计稿尺寸(微信端)
    4105: [Thu Summer Camp 2015]平方运算
  • 原文地址:https://www.cnblogs.com/gcb999/p/3229871.html
Copyright © 2011-2022 走看看