わかりました私は困惑しています。iOS アプリで Core Plot 1.2 を使用しようとしていますが、1 つの画面に 2 つのプロットを追加しようとしています。私のView Controllerのコードは以下の通りです。NIB ファイルもありますが、空です - UIView だけのデフォルト ビューです。タイプ CPTGraphHostingView の 2 つのサブビューを作成し、これらを self.view の suvview として追加してから、グラフを作成します。以下のコードでは、グラフの 1 つを作成するメソッドをコメントアウトして、表示するグラフを 1 つでも取得できるかどうかを確認しましたが、表示されるのは空白の白い画面だけです。
各プロットのテスト目的で単純な X**2 関数を使用しています。
私は何を間違っていますか?2 つまたは 3 つの別々の XY スタイル プロットを 1 つの画面に表示する簡単な方法はありますか?
@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];
****/
}