2012-12-26 2 views
4

이 작업을 수행하는 방법에 대한 몇 가지 예를 둘러 보았지만 작동하지 못하는 것 같습니다. 아무리해도 그래프의 오른쪽에 다른 축을 표시 할 수 없습니다. 나는 그것이 어리석은 짓일지도 모른다고 느낀다.왼쪽 및 오른쪽 Y 축이있는 코어 플롯 차트

다음은 그래프를 생성하는 데 사용되는 모든 코드입니다. 저는 하루에 몇 시간 동안 값을 그래프로 나타냅니다. 결국 각 Y 축은 다른 축척을 갖지만 순간에는 다른 축을 표시하기를 원합니다.

CPTXYGraph *graph = [[CPTXYGraph alloc] initWithFrame:CGRectZero xScaleType:CPTScaleTypeDateTime yScaleType:CPTScaleTypeLinear]; 

CPTTheme *theme = [CPTTheme themeNamed:@"CustomTheme"]; 
[graph applyTheme:theme]; 

graph.paddingLeft = 2.0; 
graph.paddingTop = 2.0; 
graph.paddingRight = 2.0; 
graph.paddingBottom = 2.0; 

graph.plotAreaFrame.paddingLeft = 30.0; 
graph.plotAreaFrame.paddingTop = 20.0; 
graph.plotAreaFrame.paddingRight = 15.0; 
graph.plotAreaFrame.paddingBottom = 30.0; 

UIColor *darkTextColor = [UIColor colorWithRed:0.325 green:0.322 blue:0.333 alpha:1.000]; 

CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle]; 
textStyle.color = [CPTColor colorWithCGColor:[darkTextColor CGColor]]; 
textStyle.fontSize = 10.0; 
graph.titleTextStyle = textStyle; 
graph.titleDisplacement = CGPointMake(0.0f, -10.0f); 
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop; 

// Setup plot space 
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace; 
plotSpace.allowsUserInteraction = NO; 
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(24.0 * D_HOUR)]; 
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(400.0)]; 

CPTXYPlotSpace *plotSpace2 = [[CPTXYPlotSpace alloc] init]; 
plotSpace2.xRange = plotSpace.xRange; 
plotSpace2.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(400.0)]; 
[graph addPlotSpace:plotSpace2]; 

// Set axis styles 
CPTXYAxis *leftY = [(CPTXYAxisSet *)graph.axisSet yAxis]; 
CPTXYAxis *x = [(CPTXYAxisSet *)graph.axisSet xAxis]; 

CPTXYAxis *rightY = [(CPTXYAxis *)[CPTXYAxis alloc] initWithFrame:CGRectZero]; 
rightY.coordinate = CPTCoordinateY; 
rightY.plotSpace = plotSpace2; 
rightY.orthogonalCoordinateDecimal = CPTDecimalFromFloat(24.0 * D_HOUR); 

graph.axisSet.axes = @[x,leftY,rightY]; 

x.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(24.0 * D_HOUR)]; 
x.majorIntervalLength = CPTDecimalFromInt(D_HOUR * 2); 
x.labelOffset = 3.0f; 
x.titleOffset = 25.0f; 
NSDateFormatter *rawFormatter = [[NSDateFormatter alloc] init]; 
[rawFormatter setDateFormat:@"ha"]; 
CPTTimeFormatter *timeFormatter = [[CPTTimeFormatter alloc] initWithDateFormatter:rawFormatter]; 
x.labelFormatter = timeFormatter; 

leftY.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(400.0)]; 
leftY.gridLinesRange = x.visibleRange; 
leftY.majorIntervalLength = CPTDecimalFromInt(40); 
leftY.titleLocation = CPTDecimalFromFloat(20.0); 
leftY.titleOffset = 14.0f; 
NSNumberFormatter *noDecimalFormatter = [[NSNumberFormatter alloc] init]; 
[noDecimalFormatter setNumberStyle:NSNumberFormatterNoStyle]; 
leftY.labelFormatter = noDecimalFormatter; 

// Skin right y 
rightY.labelingPolicy = CPTAxisLabelingPolicyFixedInterval; 
rightY.majorIntervalLength = CPTDecimalFromInt(50); 
rightY.minorTicksPerInterval = 2; 
rightY.orthogonalCoordinateDecimal = CPTDecimalFromDouble(0.0); 
rightY.tickDirection = CPTSignNegative; 
rightY.majorTickLineStyle = leftY.majorTickLineStyle; 
rightY.minorTickLineStyle = nil; 
rightY.axisLineStyle = leftY.axisLineStyle; 
rightY.majorTickLength = 2.0; 
rightY.minorTickLength = 1.0; 
rightY.labelTextStyle = leftY.labelTextStyle; 
rightY.titleTextStyle = leftY.titleTextStyle; 
rightY.majorGridLineStyle = leftY.majorGridLineStyle; 
rightY.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(400.0)]; 
rightY.gridLinesRange = x.visibleRange; 
rightY.majorIntervalLength = CPTDecimalFromInt(40); 
rightY.labelFormatter = noDecimalFormatter; 

// Create plot 
CPTScatterPlot *hourlyPlot = [[CPTScatterPlot alloc] initWithFrame:graph.bounds]; 
CPTMutableLineStyle *dataStyle = [hourlyPlot.dataLineStyle mutableCopy]; 
dataStyle.lineWidth = 2.0f; 
dataStyle.lineColor = [CPTColor colorWithCGColor:[darkTextColor CGColor]]; 
hourlyPlot.dataLineStyle = [dataStyle copy]; 
hourlyPlot.dataSource = self; 
[graph addPlot:hourlyPlot]; 

답변

4

오른쪽 y 축의 orthogonalCoordinateDecimal을 두 번 설정합니다. 두 번째로, 다른 쪽 위에 왼쪽으로 돌아갑니다.

+0

Doh! 내가 그걸 놓쳤다는 것을 믿을 수 없어. 그게 바보 같은 짓인지 알았어. –

관련 문제