1
我有兩個問題。軸位置和繪圖顏色
我的軸不能滿足於適當的點即我希望我的y軸的0相交的x軸的第一個值。我通過
orthogonalCoordinateDecimal
屬性嘗試了很多方法,但我無法管理它。其次,我右邊的第二個圖不是紅色的繪圖,因爲我已經編碼了。你能告訴我我可能會錯過什麼嗎?
圖:
的我的代碼片段採寫:
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];
任何幫助將是appreciated.Thanks。
三江源@Eric Skroch。我的第二個問題解決了。我只是盲目地複製第二個情節的代碼。我編輯了我的起始代碼以獲取更多詳細信息。 – NightFury
你能否考慮與此有關的另一個問題...?我在'y2'軸之後添加了四行以將y2添加到軸集。當我試圖通過使用上面的代碼在條形圖中配置我的軸時,這些行會崩潰我的程序。我需要爲條形圖繪製多個y軸,就像圖中一樣。 – NightFury
您是否設置了任何軸約束?如果是這樣,約束將覆蓋'orthogonalCoordinateDecimal'。 –