2010-02-01 2 views

답변

2

막대 그래프와 비슷합니다. barsAreHorizontal = NO을 설정하여 수직 막대를 만듭니다. 모양을 사용자 정의하려면 barWidth, lineStylefill을 사용하십시오. 몇 가지 예제 프로그램은 막대 그래프를 사용하여 아이디어를 찾습니다.

+0

바 플롯에 대한 나의 이해는 데이터 범위를 버킷으로 나누고 각 버킷의 평균 y 값을 표시한다는 것입니다. 바는 전체 범위를 커버합니다. 내 응용 프로그램의 경우 해당 점의 y 값과 동일한 높이를 가진 모든 데이터 요소에 대해 선을 표시하고 싶습니다. 제가 막대 그래프로 이것을 할 수 있다면, 그것은 멋질 것입니다. – Jacko

0

나는 이것이 당신을 도울 것 같아요.

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.title = @"Core-Plot"; 

    graph = [[CPXYGraph alloc] initWithFrame:CGRectZero]; 
    CPTheme *theme = [CPTheme themeNamed:kCPDarkGradientTheme]; 
    [graph applyTheme:theme]; 

    CGAffineTransform verticalFlip = CGAffineTransformMakeScale(1,-1); 

    UILabel *lbl; 
    for(int i = 21; i <= 24; i++){ 

     lbl = (UILabel *)[self.view viewWithTag:i]; 
     lbl.transform = CGAffineTransformTranslate(verticalFlip, 0, -300); 
    } 

    CPLayerHostingView *hostingView = (CPLayerHostingView *)self.view; 
    hostingView.hostedLayer = graph; 
    graph.plotArea.masksToBorder = NO; 

    graph.paddingLeft = 50.0; 
    graph.paddingTop = 60.0; 
    graph.paddingRight = 20.0; 
    graph.paddingBottom = 50.0; 

    CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace; 
    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0) length:CPDecimalFromFloat(6)]; 
    plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0) length:CPDecimalFromFloat(([[expectedCigArray objectAtIndex:0] floatValue]+5))]; 
    plotSpace.allowsUserInteraction=YES; 

    CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet; 
    CPXYAxis *x = axisSet.xAxis; 
    x.axisLineStyle = nil; 
    x.majorTickLineStyle = nil; 
    x.minorTickLineStyle = nil; 
    x.majorIntervalLength = CPDecimalFromString(@"1"); 
    x.constantCoordinateValue = CPDecimalFromString(@"0"); 
    x.title = @"Days"; 
    x.titleLocation = CPDecimalFromFloat(1.5f); 

    CPXYAxis *y = axisSet.yAxis; 
    y.axisLineStyle = nil; 
    y.majorTickLineStyle = nil; 
    y.minorTickLineStyle = nil; 
    y.majorIntervalLength = CPDecimalFromString(@"5"); 
    y.constantCoordinateValue = CPDecimalFromString(@"0"); 
    y.title = @"Money"; 
    y.titleOffset = 30.0f; 
    y.titleLocation = CPDecimalFromFloat(10.0f); 


    CPBarPlot *expectedMoney = [CPBarPlot tubularBarPlotWithColor:[CPColor darkGrayColor] horizontalBars:NO]; 
    expectedCigPlot.identifier = @"expectedCigPlot"; 
    expectedCigPlot.cornerRadius = 2.0f; 
    expectedCigPlot.barWidth = 15.0f; 
    expectedCigPlot.dataSource = self; 
    [graph addPlot:expectedCigPlot toPlotSpace:plotSpace]; 

} 


-(NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot{ 
    return (moneyArray.count + 1); 
} 

-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index 
{ 
    if(fieldEnum == CPScatterPlotFieldX) 
    { 
     return [NSNumber numberWithInt: index]; 
    } 
    else 
    { 
     if(plot.identifier == @"money") 
     { 
      if(index == 0) 
       return [NSNumber numberWithDouble:0.0]; 
      return [NSNumber numberWithDouble:[[moneyArray objectAtIndex:(index-1)] doubleValue]]; 
     } 

    } 
} 

위의 코드 돈 배열에는 money 값이 있습니다. 따라서 배열의 y 값을 전달하면 목적이 해결 될 수 있습니다.

관련 문제