Ok 나는 뒤죽박죽입니다. 내 iOS 앱에서 Core Plot 1.2를 사용하려고하는데 한 화면에 두 개의 플롯을 추가하려고합니다. 내 View Controller 용 코드는 다음과 같습니다. NIB 파일도 있지만 비어 있습니다. UIView의 기본보기입니다. CPTGraphHostingView 유형의 두 가지 하위 뷰를 만들고 self.view의 suvviews로 추가 한 다음 그래프를 만듭니다. 아래의 코드에서 심지어 하나의 그래프를 표시 할 수 있는지를 알기 위해 그래프 중 하나를 만드는 메소드를 주석 처리했습니다.하지만 빈 흰색 스크린이 표시됩니다.하나의 화면에 여러 개의 코어 플롯 플롯을 추가하는 방법
각 플롯에 대한 테스트 목적으로 간단한 X ** 2 함수를 사용하고 있습니다.
내가 뭘 잘못하고 있니? 2 개 또는 3 개의 별도 XY 스타일 플롯을 단일 스크린에 표시하는 쉬운 방법이 있습니까?
@interface SensorPlotSecondViewController : UIViewController <CPTPlotDataSource>
{
CPTGraphHostingView *accelSubview;
CPTGraphHostingView *gyroSubview;
CPTGraphHostingView *magSubview;
CPTXYGraph *accelGraph;
CPTXYGraph *gyroGraph;
CPTXYGraph *magGraph;
}
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot;
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx;
@end
@implementation SensorPlotSecondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Second", @"Second");
self.tabBarItem.image = [UIImage imageNamed:@"second"];
CGRect frm1=CGRectMake(0,0,320,150);
accelSubview=[[CPTGraphHostingView alloc] initWithFrame:frm1];
[self.view addSubview:accelSubview];
CGRect frm2=CGRectMake(0,150,320,150);
gyroSubview=[[CPTGraphHostingView alloc] initWithFrame:frm2];
[self.view addSubview:gyroSubview];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self createAccelGraph];
//[self createGyroGraph];
}
-(void)createAccelGraph
{
accelGraph = [[CPTXYGraph alloc] initWithFrame: accelSubview.bounds];
//CPTTheme *theme=[CPTTheme themeNamed:kCPTPlainWhiteTheme];
//[accelGraph applyTheme:theme];
accelGraph.plotAreaFrame.borderLineStyle = nil;
CPTGraphHostingView *hostingView = (CPTGraphHostingView *)accelSubview;
hostingView.hostedGraph=accelGraph;
accelGraph.paddingLeft = 0.0;
accelGraph.paddingTop = 0.0;
accelGraph.paddingRight = 0.0;
accelGraph.paddingBottom = 0.0;
//accelGraph.fill=nil;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)accelGraph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0)
length:CPTDecimalFromFloat(10)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0)
length:CPTDecimalFromFloat(30)];
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.lineColor = [CPTColor blackColor];
lineStyle.lineWidth = 2.0f;
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)accelGraph.axisSet;
axisSet.xAxis.majorIntervalLength = CPTDecimalFromString(@"5");
axisSet.xAxis.minorTicksPerInterval = 4;
axisSet.xAxis.majorTickLineStyle = lineStyle;
axisSet.xAxis.minorTickLineStyle = lineStyle;
axisSet.xAxis.axisLineStyle = lineStyle;
axisSet.xAxis.minorTickLength = 5.0f;
axisSet.xAxis.majorTickLength = 7.0f;
axisSet.xAxis.labelOffset = 3.0f;
axisSet.xAxis.visibleAxisRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromString(@"0") length:CPTDecimalFromString(@"10")];
axisSet.yAxis.majorIntervalLength = CPTDecimalFromString(@"5");
axisSet.yAxis.minorTicksPerInterval = 4;
axisSet.yAxis.majorTickLineStyle = lineStyle;
axisSet.yAxis.minorTickLineStyle = lineStyle;
axisSet.yAxis.axisLineStyle = lineStyle;
axisSet.yAxis.minorTickLength = 5.0f;
axisSet.yAxis.majorTickLength = 7.0f;
axisSet.yAxis.labelOffset = 3.0f;
axisSet.yAxis.visibleAxisRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromString(@"0") length:CPTDecimalFromString(@"25")];
accelGraph.plotAreaFrame.paddingLeft = 40.0;
accelGraph.plotAreaFrame.paddingTop = 80.0;
accelGraph.plotAreaFrame.paddingRight = 40.0;
accelGraph.plotAreaFrame.paddingBottom = 300.0;
CPTScatterPlot *xSquaredPlot = [[[CPTScatterPlot alloc] initWithFrame:accelSubview.bounds] autorelease];
//CPTScatterPlot *xSquaredPlot = [[[CPTScatterPlot alloc] init] autorelease];
xSquaredPlot.identifier = @"X Squared Plot";
CPTMutableLineStyle *dataLineStyle = [CPTMutableLineStyle lineStyle];
dataLineStyle.lineWidth = 1.0f;
dataLineStyle.lineColor = [CPTColor redColor];
xSquaredPlot.dataLineStyle=dataLineStyle;
xSquaredPlot.dataSource = self;
[accelGraph addPlot:xSquaredPlot];
CPTPlotSymbol *greenCirclePlotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
greenCirclePlotSymbol.fill = [CPTFill fillWithColor:[CPTColor greenColor]];
greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
//xSquaredPlot.defaultPlotSymbol = greenCirclePlotSymbol;
xSquaredPlot.plotSymbol = greenCirclePlotSymbol;
/****
CPTScatterPlot *xInversePlot = [[[CPTScatterPlot alloc] init] autorelease];
xInversePlot.identifier = @"X Inverse Plot";
CPTMutableLineStyle *dataLineStyle2 = [CPTMutableLineStyle lineStyle];
dataLineStyle2.lineWidth = 1.0f;
dataLineStyle2.lineColor = [CPTColor blueColor];
xInversePlot.dataLineStyle=dataLineStyle2;
xInversePlot.dataSource = self;
[accelGraph addPlot:xInversePlot];
****/
}
-(void)createGyroGraph
{
gyroGraph = [[CPTXYGraph alloc] initWithFrame: gyroSubview.bounds];
CPTTheme *theme=[CPTTheme themeNamed:kCPTPlainWhiteTheme];
[gyroGraph applyTheme:theme];
gyroGraph.plotAreaFrame.borderLineStyle = nil;
CPTGraphHostingView *hostingView = (CPTGraphHostingView *)gyroSubview;
hostingView.hostedGraph=gyroGraph;
gyroGraph.paddingLeft = 0.0;
gyroGraph.paddingTop = 0.0;
gyroGraph.paddingRight = 0.0;
gyroGraph.paddingBottom = 0.0;
gyroGraph.fill=nil;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)gyroGraph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0)
length:CPTDecimalFromFloat(10)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0)
length:CPTDecimalFromFloat(30)];
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.lineColor = [CPTColor blackColor];
lineStyle.lineWidth = 2.0f;
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)gyroGraph.axisSet;
axisSet.xAxis.majorIntervalLength = CPTDecimalFromString(@"5");
axisSet.xAxis.minorTicksPerInterval = 4;
axisSet.xAxis.majorTickLineStyle = lineStyle;
axisSet.xAxis.minorTickLineStyle = lineStyle;
axisSet.xAxis.axisLineStyle = lineStyle;
axisSet.xAxis.minorTickLength = 5.0f;
axisSet.xAxis.majorTickLength = 7.0f;
axisSet.xAxis.labelOffset = 3.0f;
axisSet.xAxis.visibleAxisRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromString(@"0") length:CPTDecimalFromString(@"10")];
axisSet.yAxis.majorIntervalLength = CPTDecimalFromString(@"5");
axisSet.yAxis.minorTicksPerInterval = 4;
axisSet.yAxis.majorTickLineStyle = lineStyle;
axisSet.yAxis.minorTickLineStyle = lineStyle;
axisSet.yAxis.axisLineStyle = lineStyle;
axisSet.yAxis.minorTickLength = 5.0f;
axisSet.yAxis.majorTickLength = 7.0f;
axisSet.yAxis.labelOffset = 3.0f;
axisSet.yAxis.visibleAxisRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromString(@"0") length:CPTDecimalFromString(@"25")];
gyroGraph.plotAreaFrame.paddingLeft = 40.0;
gyroGraph.plotAreaFrame.paddingTop = 200.0;
gyroGraph.plotAreaFrame.paddingRight = 40.0;
gyroGraph.plotAreaFrame.paddingBottom = 150.0;
CPTScatterPlot *xSquaredPlot = [[[CPTScatterPlot alloc] initWithFrame:gyroSubview.bounds] autorelease];
//CPTScatterPlot *xSquaredPlot = [[[CPTScatterPlot alloc] init] autorelease];
xSquaredPlot.identifier = @"X Squared Plot";
CPTMutableLineStyle *dataLineStyle = [CPTMutableLineStyle lineStyle];
dataLineStyle.lineWidth = 1.0f;
dataLineStyle.lineColor = [CPTColor redColor];
xSquaredPlot.dataLineStyle=dataLineStyle;
xSquaredPlot.dataSource = self;
[gyroGraph addPlot:xSquaredPlot];
CPTPlotSymbol *greenCirclePlotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
greenCirclePlotSymbol.fill = [CPTFill fillWithColor:[CPTColor greenColor]];
greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
//xSquaredPlot.defaultPlotSymbol = greenCirclePlotSymbol;
xSquaredPlot.plotSymbol = greenCirclePlotSymbol;
/****
CPTScatterPlot *xInversePlot = [[[CPTScatterPlot alloc] init] autorelease];
xInversePlot.identifier = @"X Inverse Plot";
CPTMutableLineStyle *dataLineStyle2 = [CPTMutableLineStyle lineStyle];
dataLineStyle2.lineWidth = 1.0f;
dataLineStyle2.lineColor = [CPTColor blueColor];
xInversePlot.dataLineStyle=dataLineStyle2;
xInversePlot.dataSource = self;
[accelGraph addPlot:xInversePlot];
****/
}
미래를위한 조언 : corePlot 데모 프로젝트에서 가장 적절한 예를 찾아 단계별로 수정하십시오. – DanSkeel