您的位置:首页 > 移动开发 > IOS开发

ios中core Plot (2)

2013-08-01 14:02 28 查看
#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: