-1
我想在我的iphone應用程序中顯示線圖。我被建議核心情節是一個很好的開源庫。所以我試着用它顯示非常基本的圖形,但圖形沒有顯示出來,只有黑屏出來。以下是我使用可可觸摸核心散點圖不顯示iOS
ChartViewController.h代碼
#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"
@interface ChartViewController : UIViewController<CPTPlotDataSource>
@end
ChartViewController.m
#import "ChartViewController.h"
CPTXYGraph *graph;
CPTGraphHostingView *graphHost;
CPTScatterPlot *dataSourceLinePlot;
NSMutableArray *xdata;
NSMutableArray *ydata;
@implementation ChartViewController
- (id)init{
self = [super initWithNibName:nil bundle:nil];
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self initializeData];
NSLog(@"viewdidloaded with number of records= %i",xdata.count);
graph = [[CPTXYGraph alloc]initWithFrame:self.view.bounds];
graphHost = [[CPTGraphHostingView alloc]initWithFrame:self.view.bounds];
dataSourceLinePlot = [[CPTScatterPlot alloc] initWithFrame:graph.bounds];
dataSourceLinePlot.identifier = @"Data Source Plot";
dataSourceLinePlot.dataSource = self;
[graph addPlot:dataSourceLinePlot];
graphHost.hostedGraph = graph;
self.view = graphHost;
}
- (void)initializeData{
xdata = [[NSMutableArray alloc]init];
ydata = [[NSMutableArray alloc]init];
for(int i=0;i<4;i++){
[xdata addObject:[NSNumber numberWithInt:i]];
[ydata addObject:[NSNumber numberWithInt:i*5]];
}
}
- (NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
NSUInteger count = (NSUInteger)[xdata count];
NSLog(@"inside number of recordsfor plot");
return count;
}
- (NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {
NSDecimalNumber *num = nil;
num = (NSDecimalNumber *)[NSNumber numberWithInteger:index];
NSLog(@"inside number for plot");
return num;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
我會很感激,如果有人可以幫我這個問題,因爲我這個環境是新的。 謝謝
嗨eric, 解決了這個問題。我不得不添加這一行 self.view.backgroundColor = [UIColor whiteColor]; 我猜默認背景是黑色的,情節的顏色也是黑色的,這就是爲什麼整個屏幕看起來都是黑色的。 愚蠢的錯誤 – Anurag 2013-03-02 12:51:36
andcourse,我也不得不添加託管視圖作爲子視圖 謝謝 – Anurag 2013-03-02 13:00:29