2014-07-21 2 views
0

내 응용 프로그램에서 코어 플롯 라이브러리를 구현합니다. 그래프에서 음수 부분을 제거하려면 Google에서 많은 검색을하지만 답변을 찾을 수 없습니다. 그래프의 음수 값은 그래프를 아래로 스크롤 할 때 표시되고 왼쪽으로 스크롤 할 때도 표시됩니다. 여기 내 코드CorePlot을 사용하여 그래프에서 음의 부분을 제거하고 싶습니까?

-(void)drawGraph{ 

    graph = [[CPTXYGraph alloc] initWithFrame:self.view.bounds]; 

    CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme]; 
    [graph applyTheme:theme]; 

    hostingView1 = [[CPTGraphHostingView alloc] initWithFrame:self.view.bounds]; 
    hostingView1.hostedGraph = graph; 
    if ([[UIScreen mainScreen] bounds].size.height == 568){ 
     hostingView1.frame = CGRectMake(15, 5, 290, 220); 
    } 
    else{ 
    hostingView1.frame = CGRectMake(15, 3, 290, 135); 
    } 
    [myGraphView addSubview:hostingView1]; 
    [myGraphView addSubview:lbl1]; 
    [myGraphView addSubview:lbl2]; 

    [lbl1 setTransform:CGAffineTransformMakeRotation(-M_PI/2)]; 
    [hostingView1 release]; 


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

    graph.plotAreaFrame.paddingLeft = 35.0 ; 
    graph.plotAreaFrame.paddingTop = 20.0 ; 
    graph.plotAreaFrame.paddingRight = 5.0 ; 
    graph.plotAreaFrame.paddingBottom = 30 ; 

    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace; 
    plotSpace.allowsUserInteraction = YES; 

    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(50.0)]; 
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(10.0)]; 

    CPTXYAxisSet *axisSet = (CPTXYAxisSet *) graph.axisSet ; 
    CPTXYAxis *x = axisSet.xAxis ; 
    x. minorTickLineStyle = nil ; 

    x. majorIntervalLength = CPTDecimalFromString (@"10"); 

    x. orthogonalCoordinateDecimal = CPTDecimalFromString (@"0"); 

    CPTXYAxis *y = axisSet.yAxis ; 

    y. minorTickLineStyle = nil ; 

    y. majorIntervalLength = CPTDecimalFromString (@"2"); 

    y. orthogonalCoordinateDecimal = CPTDecimalFromString (@"0"); 

    dataSourceLinePlot = [[[CPTScatterPlot alloc] init] autorelease]; 
    dataSourceLinePlot.identifier = @"Green Plot"; 

    CPTMutableLineStyle *lineStyle = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease]; 
    lineStyle.lineWidth = 0.3f; 
    lineStyle.lineColor = [CPTColor orangeColor]; 
    dataSourceLinePlot.dataLineStyle = lineStyle; 

    dataSourceLinePlot.opacity = 0.0f; 

    dataSourceLinePlot.dataSource = self; 
    [graph addPlot:dataSourceLinePlot]; 

    CPTGradient *areaGradient = [ CPTGradient gradientWithBeginningColor :[CPTColor orangeColor] endingColor :[CPTColor colorWithComponentRed:0.55 green:0.55 blue:0.16 alpha:0.0]]; 

    areaGradient.angle = -00.0f ; 

    CPTFill *areaGradientFill = [ CPTFill fillWithGradient :areaGradient]; 

    dataSourceLinePlot. areaFill = areaGradientFill; 
    dataSourceLinePlot. areaBaseValue = CPTDecimalFromString (@"0.0"); 
    dataSourceLinePlot.interpolation = CPTScatterPlotInterpolationLinear ; 


} 

답변

1

이다보기/그래프가 CPTPlotSpaceDelegate 프로토콜 채택 처리 객체 유무 :

@interface YourViewController() <CPTPlotSpaceDelegate> 

는 그 다음 plotspace의 대리인에게 컨트롤러를 지정 : 마지막으로

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace; 
plotSpace.allowsUserInteraction = YES; 
[plotSpace setDelegate:self]; 

을, 컨트롤러에 CPTPlotSpaceDelegate 함수 "willChangePlotRangeTo"를 구현하게하십시오.

-(CPTPlotRange*)plotSpace:(CPTPlotSpace *)space willChangePlotRangeTo:(CPTPlotRange *)newRange forCoordinate:(CPTCoordinate)coordinate 
{ 
    if([newRange locationDouble] < 0) 
    { 
     if(coordinate == CPTCoordinateX) 
      return [(CPTXYPlotSpace*)space xRange]; 
     else if(coordinate == CPTCoordinateY) 
      return [(CPTXYPlotSpace*)space yRange]; 
    } 
    return newRange; 
} 

이렇게하면 현재 플롯 범위를 반환하여 플롯 공간이 더 이상 스크롤되지 않습니다. 어느 한 축에 대해 변경해야한다고 결정해야한다면 원하는 하한 경계를 선언 할 수 있습니다.