2015-01-12 6 views
-1

저는 산란 플롯과 막대 그래프로 된 그래프를 가지고 있으며 두 개의 y 축을 가지고 있습니다. 나는 y 축 움직임없이 수평으로 스크롤 할 수 있도록 wnt했다. 하나의 y 축 만 있으면 코드가 작동하지만 두 번째 코드를 추가하면 작동합니다. 두 번째는 여전히 위아래로 움직입니다. 너 좀 이상하니?두 개의 비늘이있는 두 개의 y 축으로 가로로 스크롤하십시오.

-(void) configureAxes:(CPTGraphHostingView *)layerHostingView withTheme:(CPTTheme *)theme{ 
    [super configureAxes:layerHostingView withTheme:theme]; 
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *) layerHostingView.hostedGraph.axisSet; 
    CPTAxis *x = axisSet.xAxis; 
    CPTAxis *y = axisSet.yAxis; 
    y.labelingPolicy = CPTAxisLabelingPolicyAutomatic; 
    x.labelingPolicy= CPTAxisLabelingPolicyNone; 
    NSMutableSet *xLabels = [NSMutableSet setWithCapacity:self.selectedExplYear.exploitation.count]; 
    NSMutableSet *xLocations = [NSMutableSet setWithCapacity:self.selectedExplYear.exploitation.count]; 

    for (int i = 0; i<self.selectedExplYear.exploitation.count; i++) { 
     SCExploitation *tech = self.selectedExplYear.exploitation[i]; 
     NSDateFormatter *df = [[NSDateFormatter alloc] init]; 
     [df setDateFormat:@"MMMM"]; 
     NSDate *dateExploitation = [NSDate dateWithTimeIntervalSince1970:tech.exploitationDate.doubleValue/1000]; 
     NSString *mois = [df stringFromDate:dateExploitation]; 
     CPTAxisLabel *label = [[CPTAxisLabel alloc]initWithText:[NSString stringWithFormat:@"%@", mois] textStyle:x.labelTextStyle]; 
     CGFloat location = i; 
     label.tickLocation = CPTDecimalFromCGFloat(location); 
     label.offset = x.majorTickLength; 
     if (label) { 
      [xLabels addObject:label]; 
      [xLocations addObject:[NSNumber numberWithFloat:location]]; 
     } 

    } 
    NSNumberFormatter *Xformatter = [[NSNumberFormatter alloc] init]; 
    [Xformatter setGeneratesDecimalNumbers:NO]; 
    [Xformatter setNumberStyle:NSNumberFormatterDecimalStyle]; 
    y.labelFormatter = Xformatter; 
    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) layerHostingView.hostedGraph.defaultPlotSpace; 
    CPTMutableTextStyle *axisTitleStyle = [CPTMutableTextStyle textStyle]; 
    axisTitleStyle.color = [CPTColor whiteColor]; 
    axisTitleStyle.fontName = @"Helvetica-Bold"; 
    axisTitleStyle.fontSize = 14.0f; 
    CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle]; 
    axisLineStyle.lineWidth = 2.0f; 
    axisLineStyle.lineColor = [CPTColor whiteColor]; 
    CPTMutableTextStyle *axisTextStyle = [[CPTMutableTextStyle alloc] init]; 
    axisTextStyle.color = [CPTColor whiteColor]; 
    axisTextStyle.fontName = @"Helvetica-Bold"; 
    axisTextStyle.fontSize = 14.0f; 
    CPTMutableLineStyle *tickLineStyle = [CPTMutableLineStyle lineStyle]; 
    tickLineStyle.lineColor = [CPTColor whiteColor]; 
    tickLineStyle.lineWidth = 2.0f; 
    tickLineStyle.lineColor = [CPTColor blackColor]; 
    tickLineStyle.lineWidth = 1.0f; 

    x.axisLabels=xLabels; 
    x.majorTickLocations = xLocations; 
    axisSet.yAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:5]; 
    y.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0) length:CPTDecimalFromDouble(250)]; 

    CPTXYAxis *y2 = [[CPTXYAxis alloc] init]; 
    y2.coordinate = CPTCoordinateY; 
    y2.plotSpace = self.scatterGraphPlotSpace; 
    y2.axisConstraints = [CPTConstraints constraintWithUpperOffset:0]; 
    y2.labelingPolicy = CPTAxisLabelingPolicyFixedInterval; 
    y2.axisLineStyle = axisLineStyle; 
    y2.majorTickLineStyle = axisLineStyle; 
    y2.title = @"Km"; 
    y2.majorIntervalLength = CPTDecimalFromFloat((80 - 0)/5.0f); 
    y2.labelFormatter = Xformatter; 
    y2.titleTextStyle = axisTextStyle; 
    y2.labelTextStyle = axisTextStyle; 
    y2.tickDirection    = CPTSignNone; 
    y2.tickLabelDirection   = CPTSignPositive; 
    y2.orthogonalCoordinateDecimal = CPTDecimalFromFloat(5.0); 
    y2.titleOffset     = 16.0 * CPTFloat(-2.1); 
    y2.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0) length:CPTDecimalFromDouble(80)]; 

    self.scatterGraphPlotSpace.xRange = plotSpace.xRange; 
    layerHostingView.hostedGraph.axisSet.axes = [NSArray arrayWithObjects:x, y, y2, nil]; 


} 


-(void)configurePlots:(CPTGraphHostingView *)layerHostingView withTheme:(CPTTheme *)theme 
{ 
    CPTGraph *graph = layerHostingView.hostedGraph; 
    CPTBarPlot *barPlotTotalDetenteEau = [CPTBarPlot tubularBarPlotWithColor:[CPTColor blueColor] horizontalBars:NO]; 
    barPlotTotalDetenteEau.identifier = DETENTEEAUIDENTIFIER; 
    CPTMutableLineStyle *lsEauPotable = [[CPTMutableLineStyle alloc]init]; 
    lsEauPotable.lineColor = [CPTColor lightGrayColor]; 
    lsEauPotable.lineWidth = 0.5; 
    barPlotTotalDetenteEau.lineStyle = lsEauPotable; 
    barPlotTotalDetenteEau.dataSource =self; 
    barPlotTotalDetenteEau.delegate = self; 
    barPlotTotalDetenteEau.zPosition = 90; 
    barPlotTotalDetenteEau.labelOffset = LABELOFFSET; 
    barPlotTotalDetenteEau.title = NSLocalizedString(@"exploitation_detente_eau", nil); 
    barPlotTotalDetenteEau.barWidth = CPTDecimalFromDouble(BARWIDTH); 
    barPlotTotalDetenteEau.barOffset = CPTDecimalFromDouble(0); 
    [graph addPlot:barPlotTotalDetenteEau toPlotSpace:graph.defaultPlotSpace]; 


    CPTBarPlot *barPlotTotalControleGaz = [CPTBarPlot tubularBarPlotWithColor:[CPTColor yellowColor] horizontalBars:NO]; 
    barPlotTotalControleGaz.identifier = CONTROLEGAZIDENTIFIER; 
    CPTMutableLineStyle *lsNouveau = [[CPTMutableLineStyle alloc]init]; 
    lsNouveau.lineColor = [CPTColor lightGrayColor]; 
    lsNouveau.lineWidth = 0.5; 
    barPlotTotalControleGaz.lineStyle = lsNouveau; 
    barPlotTotalControleGaz.dataSource =self; 
    barPlotTotalControleGaz.delegate = self; 
    barPlotTotalControleGaz.zPosition = 100; 
    barPlotTotalControleGaz.labelOffset = LABELOFFSET; 
    barPlotTotalControleGaz.title = NSLocalizedString(@"exploitation_controle_gaz", nil); 
    barPlotTotalControleGaz.barWidth = CPTDecimalFromDouble(BARWIDTH); 
    barPlotTotalControleGaz.barOffset = CPTDecimalFromDouble(BARWIDTH+0.01); 
    [graph addPlot:barPlotTotalControleGaz toPlotSpace:graph.defaultPlotSpace]; 


    self.scatterGraphPlotSpace = [[CPTXYPlotSpace alloc] init]; 
    self.scatterGraphPlotSpace.allowsUserInteraction =YES; 
    // self.scatterGraphPlotSpace.delegate =self; 
    CPTScatterPlot *controlerPlot = [[CPTScatterPlot alloc] init]; 
    controlerPlot.dataSource = self; 
    controlerPlot.delegate = self; 
    controlerPlot.title = NSLocalizedString(@"km_fuite", nil); 
    controlerPlot.identifier = KMCONTROLERIDENTIFIER; 
    controlerPlot.plotSymbolMarginForHitDetection = 15.0f; 
    CPTColor *effectivePlotColor = [CPTColor redColor]; 
    [graph addPlot:controlerPlot toPlotSpace:self.scatterGraphPlotSpace]; 

    CPTBarPlot *barPlotTotalControleEau = [CPTBarPlot tubularBarPlotWithColor:[CPTColor greenColor] horizontalBars:NO]; 
    barPlotTotalControleEau.identifier = CONTROLEEAUIDENTIFIER; 
    CPTMutableLineStyle *lsProvisoire = [[CPTMutableLineStyle alloc]init]; 
    lsProvisoire.lineColor = [CPTColor lightGrayColor]; 
    lsProvisoire.lineWidth = 0.5; 
    barPlotTotalControleEau.lineStyle = lsProvisoire; 
    barPlotTotalControleEau.dataSource = self; 
    barPlotTotalControleEau.delegate = self; 
    barPlotTotalControleEau.zPosition = 100; 
    barPlotTotalControleEau.labelOffset = LABELOFFSET; 
    barPlotTotalControleEau.title = NSLocalizedString(@"exploitation_controle_eau", nil); 
    barPlotTotalControleEau.barWidth = CPTDecimalFromDouble(BARWIDTH); 
    barPlotTotalControleEau.barOffset = CPTDecimalFromDouble(0); 
    [graph addPlot:barPlotTotalControleEau toPlotSpace:graph.defaultPlotSpace]; 

    CPTBarPlot *barPlotTotalDetenteGaz = [CPTBarPlot tubularBarPlotWithColor:[CPTColor grayColor] horizontalBars:NO]; 
    barPlotTotalDetenteGaz.identifier = DETENTEGAZIDENTIFIER; 
    CPTMutableLineStyle *lsAugmentation = [[CPTMutableLineStyle alloc]init]; 
    lsAugmentation.lineColor = [CPTColor lightGrayColor]; 
    lsAugmentation.lineWidth = 0.5; 
    barPlotTotalDetenteGaz.lineStyle = lsAugmentation; 
    barPlotTotalDetenteGaz.dataSource =self; 
    barPlotTotalDetenteGaz.delegate = self; 
    barPlotTotalDetenteGaz.zPosition = 70; 
    barPlotTotalDetenteGaz.labelOffset = LABELOFFSET; 
    barPlotTotalDetenteGaz.title = NSLocalizedString(@"exploitation_detente_gaz", nil); 
    barPlotTotalDetenteGaz.barWidth = CPTDecimalFromDouble(BARWIDTH); 
    barPlotTotalDetenteGaz.barOffset = CPTDecimalFromDouble(BARWIDTH+0.01); 
    [graph addPlot:barPlotTotalDetenteGaz toPlotSpace:graph.defaultPlotSpace]; 

    NSArray *plots = @[barPlotTotalDetenteEau,barPlotTotalControleEau,barPlotTotalControleGaz,barPlotTotalDetenteGaz]; 
    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace; 
    [plotSpace scaleToFitPlots:plots]; 
    CPTMutablePlotRange *xRange = [plotSpace.xRange mutableCopy]; 
    [xRange expandRangeByFactor:CPTDecimalFromCGFloat(1.3f)]; 
    xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-0.5f) length:CPTDecimalFromFloat(4.0f)]; 

    plotSpace.xRange = xRange; 
    CPTMutablePlotRange *yRange = [plotSpace.yRange mutableCopy]; 
    [yRange expandRangeByFactor:CPTDecimalFromCGFloat(1.4f)]; 
    plotSpace.yRange = yRange; 
    plotSpace.delegate = self; 

    self.scatterGraphPlotSpace.globalYRange = plotSpace.globalYRange; 
    CPTScatterPlot *visuelPlot = [[CPTScatterPlot alloc] init]; 
    visuelPlot.dataSource = self; 
    visuelPlot.delegate = self; 
    visuelPlot.title = NSLocalizedString(@"km_visuel", nil); 
    visuelPlot.identifier = KMVISUELIDENTIFIER; 
    visuelPlot.plotSymbolMarginForHitDetection = 15.0f; 
    CPTColor *budgeteePlotColor = [CPTColor orangeColor]; 


    CPTMutableLineStyle *budgeteelLineStyle = [CPTMutableLineStyle lineStyle]; // [budgeteePlot.dataLineStyle mutableCopy]; 
    budgeteelLineStyle.lineWidth = 2.5; 
    budgeteelLineStyle.lineColor = budgeteePlotColor; 
    visuelPlot.dataLineStyle = budgeteelLineStyle; 
    CPTPlotSymbol *budgeteeSymbol = [CPTPlotSymbol ellipsePlotSymbol]; 
    budgeteeSymbol.fill = [CPTFill fillWithColor:budgeteePlotColor]; 
    budgeteeSymbol.lineStyle = budgeteelLineStyle; 
    budgeteeSymbol.size = CGSizeMake(6.0f, 6.0f); 
    visuelPlot.plotSymbol = budgeteeSymbol; 

    CPTMutableLineStyle *effectiveLineStyle = [CPTMutableLineStyle lineStyle]; 
    effectiveLineStyle.lineWidth = 2.5; 
    effectiveLineStyle.lineColor = effectivePlotColor; 
    controlerPlot.dataLineStyle = effectiveLineStyle; 
    CPTPlotSymbol *effectiveSymbol = [CPTPlotSymbol ellipsePlotSymbol]; 
    effectiveSymbol.fill = [CPTFill fillWithColor:effectivePlotColor]; 
    effectiveSymbol.lineStyle = effectiveLineStyle; 
    effectiveSymbol.size = CGSizeMake(6.0f, 6.0f); 
    controlerPlot.plotSymbol = effectiveSymbol; 
    [self.scatterGraphPlotSpace scaleToFitPlots:[NSArray arrayWithObjects:controlerPlot, visuelPlot, nil]]; 
    [graph addPlot:visuelPlot toPlotSpace:self.scatterGraphPlotSpace]; 


    CPTPlotRange *globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0) length:CPTDecimalFromDouble(250)]; 
    plotSpace.globalYRange = globalYRange; 
    self.scatterGraphPlotSpace.yRange =[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) 
                    length:CPTDecimalFromFloat(80)]; 
    CPTMutablePlotRange *y2Range = [self.scatterGraphPlotSpace.yRange mutableCopy]; 
    [y2Range expandRangeByFactor:CPTDecimalFromCGFloat(1.4f)]; 
    self.scatterGraphPlotSpace.yRange = y2Range; 

    [layerHostingView.hostedGraph addPlotSpace:self.scatterGraphPlotSpace]; 
} 

-(void)configureGraph:(CPTGraphHostingView *)layerHostingView withTheme:(CPTTheme *)theme 
{ 

    CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:layerHostingView.bounds]; 
    graph.plotAreaFrame.masksToBorder = NO; 
    layerHostingView.hostedGraph = graph; 
    if(self.selectedExplYear.exploitation.count> 3){ 
     graph.defaultPlotSpace.allowsUserInteraction = YES; 
    } 
    [graph applyTheme:self.theme]; 
    graph.paddingBottom = 60.0f; 
    graph.paddingLeft = 30.0f; 
    graph.paddingTop = 30.0f; 
    graph.paddingRight = 30.0f; 
    graph.title = nil; 

} 


-(CGPoint)plotSpace:(CPTPlotSpace *)space willDisplaceBy:(CGPoint)displacement 
{ 
    return CGPointMake(displacement.x, 0); 
} 

-(CPTPlotRange *)plotSpace:(CPTPlotSpace *)space willChangePlotRangeTo:(CPTPlotRange *)newRange forCoordinate:(CPTCoordinate)coordinate 
{ 
    if (space == self.scatterGraphPlotSpace) { 
     if (coordinate == CPTCoordinateY) { 
      newRange = self.scatterGraphPlotSpace.yRange; 
     } 
    }else{ 
     if (coordinate == CPTCoordinateY) { 
      newRange = ((CPTXYPlotSpace*)space).yRange; 
     } 
    } 
    return newRange; 
} 

감사 self.scatterGraphPlotSpace에 대한 delegate 설정 많은

+0

질문에 좀 더 명확하게 답하면 더 나은 응답을 얻을 수 있습니다. 특히 코드 덤프와 모호한 문제 사양을 삭제하는 것만은 아닙니다. 최소한의 완전하고 검증 가능한 예를 시도해보십시오. – Sobrique

답변

0

:

여기 내 코드입니다. 해당 코드 행은 게시 한 코드에서 주석 처리됩니다.

관련 문제