私には2つの問題があります。
軸が適切な点で交わっていません。つまり、y 軸の 0 を x 軸の最初の値と交差させたいのです。プロパティを通じて多くの方法を試しまし
orthogonalCoordinateDecimal
たが、管理できません。第二に、右側の 2 番目のプロットは、コード化したように赤色でプロットされていません。何が欠けている可能性があるか教えていただけますか?
形:
私が書いたコードスニペット:
NSTimeInterval oneDay = 24 * 60 * 60;
// Setup plot spaces
//1- calorie
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = YES;
NSTimeInterval xLow = 0.0f;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xLow) length:CPTDecimalFromFloat(oneDay * 7.0f)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(600)];
//2- exercise
plotSpace2 = [[[CPTXYPlotSpace alloc] init] autorelease];
plotSpace2.allowsUserInteraction = YES;
plotSpace2.xRange = plotSpace.xRange;
plotSpace2.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0)
length:CPTDecimalFromFloat(60.0)];
[graph addPlotSpace:plotSpace2];
CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.graphHost.hostedGraph.axisSet;
// Axes
CPTXYAxis *x = axisSet.xAxis;
NSTimeInterval oneDay = 24 * 60 * 60;
x.majorIntervalLength = CPTDecimalFromFloat(oneDay);
x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
x.minorTicksPerInterval = 0;
CPTXYAxis *y = axisSet.yAxis;
y.majorIntervalLength = CPTDecimalFromInt(200);
y.minorTicksPerInterval = 9;
y.orthogonalCoordinateDecimal = CPTDecimalFromFloat(0);
y.title = @"Calories Burned";
CPTXYAxis *y2 = [[[CPTXYAxis alloc] init]retain];
y2.coordinate = CPTCoordinateY;
y2.majorIntervalLength = CPTDecimalFromString(@"5.0");
y2.minorTicksPerInterval = 3;
y2.orthogonalCoordinateDecimal = CPTDecimalFromString(@"-20.0");
y2.title = @"Exercise Time (min)";
//I added these lines too
//adding 2nd axis
NSMutableArray *newAxes = [graph.axisSet.axes mutableCopy];
[newAxes addObject:y2];
graph.axisSet.axes = newAxes;
[newAxes release];
CPTScatterPlot *caloriePlot = [[CPTScatterPlot alloc] init];
caloriePlot.dataSource = self;
caloriePlot.identifier = @"Calorie";
//create styles and symbols
CPTMutableLineStyle *calorieLineStyle = [caloriePlot.dataLineStyle mutableCopy];
calorieLineStyle.lineWidth = 2.5;
calorieLineStyle.lineColor = [CPTColor greenColor];
caloriePlot.dataLineStyle = calorieLineStyle;
[graph addPlot:caloriePlot toPlotSpace:plotSpace];
CPTScatterPlot *exercisePlot = [[CPTScatterPlot alloc] init];
exercisePlot.dataSource = self;
exercisePlot.identifier = @"Exercise";
CPTMutableLineStyle *exerciseLineStyle = [exercisePlot.dataLineStyle mutableCopy];
exerciseLineStyle.lineWidth = 2.5;
exerciseLineStyle.lineColor = [CPTColor redColor];
exerciseLineStyle.dashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:5.0f], [NSNumber numberWithFloat:5.0f], nil];
exercisePlot.dataLineStyle =calorieLineStyle;
[graph addPlot:exercisePlot toPlotSpace:plotSpace2];
どんな助けでも大歓迎です.Thanks.