2014-01-30 3 views
0

에 숨겨져 :절반은 내가 코어 플롯 막대 그래프 같은이 핵심 플롯

enter image description here

당신이 볼 수 있듯이 - 첫 번째 막대의 절반 y 축으로 숨겨져 있습니다. 그래프의 가시 영역 경계를 조금 더 넓게 만들려면 어떻게해야합니까?

EDIT :

- (void) drawBarPlot 
{ 
    [self configureBarGraph]; 
    [self configureBarPlot]; 
    [self configureAxes]; 
} 

- (void) configureBarGraph { 

    // 1 - Create the graph 

    CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:self.barChartView.bounds]; 
    graph.plotAreaFrame.masksToBorder = NO; 
    self.barChartView.hostedGraph = graph; 

    // 2 - Configure the graph 

    [graph applyTheme:nil]; 

    graph.paddingBottom = 0.0f; 
    graph.paddingLeft = 0.0f; 
    graph.paddingTop = 0.0f; 
    graph.paddingRight = 0.0f; 

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

    // 3 - Set up plot space 

    CGFloat xMin = 0.0f; 
    CGFloat xMax = (CGFloat)[[[[PlotDataStore sharedInstance] docsCount] valueForKey:@"docs"] count]; 
    CGFloat yMin = 0.0f; 
    CGFloat yMax = 10.0f; // should determine dynamically based on max price 
    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace; 
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xMin) length:CPTDecimalFromFloat(xMax)]; 
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yMin) length:CPTDecimalFromFloat(yMax)]; 
} 

- (void) configureBarPlot { 

    // 1 - Set up the plot 

    self.barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor darkGrayColor] horizontalBars:NO]; 

    // 2 - Set up line style 

    CPTMutableLineStyle *barLineStyle = [[CPTMutableLineStyle alloc] init]; 
    barLineStyle.lineColor = [CPTColor lightGrayColor]; 
    barLineStyle.lineWidth = 0.5; 

    // 3 - Add plots to graph 

    CPTGraph *graph = self.barChartView.hostedGraph; 

    self.barPlot.dataSource = self; 
    self.barPlot.delegate = self; 

    self.barPlot.barCornerRadius = 0.0f; 
    self.barPlot.lineStyle = barLineStyle; 
    self.barPlot.baseValue = CPTDecimalFromDouble(0.0f); 
    self.barPlot.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:100.0f/255.0f green:192.0f/255.0f blue:245.0f/255.0f alpha:1.0f]]; 

    [graph addPlot:self.barPlot toPlotSpace:(CPTPlotSpace *) graph.defaultPlotSpace]; 

} 

- (void) configureAxes { 

    // 1 - Configure styles 

    CPTMutableTextStyle *axisLabelsStyle = [CPTMutableTextStyle textStyle]; 
    axisLabelsStyle.color = [CPTColor grayColor]; 
    axisLabelsStyle.fontName = @"Helvetica"; 

    // 2 - Get the graph's axis set 

    CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.barChartView.hostedGraph.axisSet; 

    axisSet.xAxis.axisLineStyle = nil; 
    axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyNone; 
    axisSet.xAxis.labelTextStyle = axisLabelsStyle; 

    NSArray *customTickLocations = [NSArray arrayWithObjects: [NSDecimalNumber numberWithInt:0], [NSDecimalNumber numberWithInt:1], [NSDecimalNumber numberWithInt:2], [NSDecimalNumber numberWithInt:3], [NSDecimalNumber numberWithInt:4], [NSDecimalNumber numberWithInt:5], [NSDecimalNumber numberWithInt:6], [NSDecimalNumber numberWithInt:7], [NSDecimalNumber numberWithInt:8], [NSDecimalNumber numberWithInt:9], [NSDecimalNumber numberWithInt:10], [NSDecimalNumber numberWithInt:11], [NSDecimalNumber numberWithInt:11], nil]; 
    NSArray *xAxisLabels = [[[PlotDataStore sharedInstance] docsCount] valueForKey:@"dates"]; 
    NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]]; 

    for (NSNumber *tickLocation in customTickLocations) { 
     CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:[tickLocation intValue]] textStyle:axisSet.xAxis.labelTextStyle]; 
     newLabel.tickLocation = [tickLocation decimalValue]; 
     newLabel.offset = axisSet.xAxis.labelOffset + axisSet.xAxis.minorTickLength; 
     [customLabels addObject:newLabel]; 
    } 

    axisSet.xAxis.axisLabels = [NSSet setWithArray:customLabels]; 

    axisSet.yAxis.labelingPolicy = CPTAxisLabelingPolicyNone; 
    axisSet.yAxis.axisLineStyle = nil; 
    axisSet.yAxis.axisLabels = nil; 
} 

- (NSUInteger) numberOfRecordsForPlot:(CPTPlot *)plot { 

    if ([plot class] == [CPTBarPlot class]) { 
     return (NSUInteger)[[[[PlotDataStore sharedInstance] docsCount] valueForKey:@"docs"] count]; 
    } 

    return 0; 
} 

- (NSNumber *) numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index { 

    if ([plot class] == [CPTBarPlot class]) { 

     switch (fieldEnum) { 

      case CPTBarPlotFieldBarLocation: 
       return [NSNumber numberWithUnsignedInteger:index]; 
       break; 

      case CPTBarPlotFieldBarTip: 
       return (NSNumber *)[[[[PlotDataStore sharedInstance] docsCount] valueForKey:@"docs"] objectAtIndex:index]; 
       break; 

     } 
    } 
} 
+2

여기에 코드를 표시하십시오. – Retro

+0

코드로 질문을 수정했습니다. – ShurupuS

답변

1

축 plotSpace

plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(calculatedLength)]; 

또는 Y에 대한 orthogonalCoordinateDecimal 및 X의 위치는 정수 바 xRange을 설정할 수있다. 따라서 0에서 시작하는 xRange을 사용하면 첫 번째 막대가 플롯의 왼쪽 가장자리에 가운데에 배치됩니다. 이를 수정하려면 시작 위치를 -0.5로하고 길이 (마디의 수 + 1)를 만드십시오.

+0

감사합니다. 에릭, 작동합니다. 그러나 나는 사용자 정의 레이블이 있습니다 - 나는 그들의 위치를 ​​변경해야합니다. – ShurupuS

0

사용자는 디스플레이 폭에 영향을 그래프 플롯 또는 공간의 다양한 속성을 설정할 수있다. 예를 들어, 당신이

y.orthogonalCoordinateDecimal = CPTDecimalFromFloat(0); 
관련 문제