2012-09-10 165 views
1

目前我正在研究iPad應用程序,即時通過使用Core-Plot在我的iPhone應用程序中開發條形圖,然後修改了iPad的框架大小以導入iPad應用程序中的相同內容,但條形圖顯示在屏幕上小,但我想在iPad上顯示它全屏,如何解決這個問題?請幫我如何在iPad中顯示條形圖?

由於提前

我想這

iPhone

-(void) drawBarChart 
{ 

     NSLog(@"iPhone Bar chart"); 

     double xAxisLength = [barValuesArray count]; 

     barGraph = [[CPTXYGraph alloc] initWithFrame:CGRectMake(0, 50, 320, 350)]; 

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

     barGraph.plotAreaFrame.paddingLeft = 60.0; 
     barGraph.plotAreaFrame.paddingTop = 40.0; 
     barGraph.plotAreaFrame.paddingRight = 10.0; 
     barGraph.plotAreaFrame.paddingBottom = 40.0; 

     if ([selectedName isEqualToString:@"(null)"] || [selectedName isEqualToString:@""] || [selectedName isEqualToString:@"NULL"] || selectedName == @"(null)" || selectedName == NULL || selectedName == @"null" || selectedName == nil) 
     { 
      barGraph.title = [namesArray objectAtIndex:0]; 
     } 
     else 
     { 
      barGraph.title = selectedName; 
     } 

     hostingView = [[CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 10, 320, 400)]; 
     hostingView.hostedGraph = barGraph; 

     CPTMutableTextStyle *textStyle = [CPTTextStyle textStyle]; 
     textStyle.color = [CPTColor blackColor]; 
     textStyle.fontSize = 16.0f; 
     textStyle.textAlignment = CPTTextAlignmentCenter; 
     barGraph.titleTextStyle = textStyle; 
     barGraph.titleDisplacement = CGPointMake(0.0f, -10.0f); 
     barGraph.titlePlotAreaFrameAnchor = CPTRectAnchorTop; 


     CPTXYAxisSet *axisSet = (CPTXYAxisSet *)barGraph.axisSet; 
     CPTXYAxis *x = axisSet.xAxis; 
     // x.axisLineStyle = nil; 
     // x.majorTickLineStyle = nil; 
     // x.minorTickLineStyle = nil; 
     x.majorIntervalLength = CPTDecimalFromString(@"70"); 
     x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0"); 
     x.title = @"Names"; 
     x.titleLocation = CPTDecimalFromFloat(7.5f); 
     x.titleOffset = 50.0f; //25.0f; 
     x.labelRotation = M_PI/5; 
     x.labelingPolicy = CPTAxisLabelingPolicyNone; 


     NSArray *customTickLocations = [NSArray arrayWithObjects: [NSDecimalNumber numberWithInt:1], [NSDecimalNumber numberWithInt: 5], [NSDecimalNumber numberWithInt:9], [NSDecimalNumber numberWithInt:13], nil]; 


     // NSArray *xAxisLabels = [NSArray arrayWithObjects:@"Smoke", @"Nicotine", @"Tar", @"", nil]; 
     // NSUInteger labelLocation = 0; 
     //  
     // NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]]; 
     // for (NSNumber *tickLocation in customTickLocations) 
     // { 
     //  CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle]; 
     //  newLabel.tickLocation = [tickLocation decimalValue]; 
     //  newLabel.offset = x.labelOffset + x.majorTickLength; 
     //  newLabel.rotation = M_PI/xAxisLength; 
     //  [customLabels addObject:newLabel]; 
     //  [newLabel release]; 
     // } 
     //  
     // x.axisLabels = [NSSet setWithArray:customLabels]; 

     CPTXYAxis *y = axisSet.yAxis; 
     // y.axisLineStyle = nil; 
     // y.majorTickLineStyle = nil; 
     // y.minorTickLineStyle = nil; 
     y.majorIntervalLength = CPTDecimalFromString(@"100"); 
     y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0"); 
     // y.title = @"Work Status"; 
     // y.titleOffset = 40.0f; 
     // y.titleLocation = CPTDecimalFromFloat(150.0f); 


     CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) barGraph.defaultPlotSpace; 
     plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0f) length:CPTDecimalFromDouble(15.0f)]; 
     plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0f) length:CPTDecimalFromDouble(1000.0f)]; 

     CPTBarPlot *barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor blueColor] horizontalBars:NO]; 
     barPlot.plotRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0) length:CPTDecimalFromDouble(13)];//xAxisLength 
     barPlot.barOffset = CPTDecimalFromFloat(1.0f); 
     barPlot.baseValue = CPTDecimalFromString(@"0"); 
     barPlot.barWidth = CPTDecimalFromFloat(3.0f); 
     barPlot.cornerRadius = 2.0f; 
     barPlot.dataSource = self; 
     [barGraph addPlot:barPlot]; 

     [self.view addSubview:hostingView]; 

} 

iPad的條形圖:

-(void) drawBarChart 
{ 

     NSLog(@"iPAD"); 

     double xAxisLength = [barValuesArray count]; 


     barGraph = [[CPTXYGraph alloc] initWithFrame:CGRectMake(0, 50, 700, 1000)]; 

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

     barGraph.plotAreaFrame.paddingLeft = 60.0; 
     barGraph.plotAreaFrame.paddingTop = 40.0; 
     barGraph.plotAreaFrame.paddingRight = 10.0; 
     barGraph.plotAreaFrame.paddingBottom = 40.0; 

     if ([selectedName isEqualToString:@"(null)"] || [selectedName isEqualToString:@""] || [selectedName isEqualToString:@"NULL"] || selectedName == @"(null)" || selectedName == NULL || selectedName == @"null" || selectedName == nil) 
     { 
      barGraph.title = [namesArray objectAtIndex:0]; 
     } 
     else 
     { 
      barGraph.title = selectedName; 
     } 

     hostingView = [[CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 10, 700, 1000)]; 
     hostingView.hostedGraph = barGraph; 

     CPTMutableTextStyle *textStyle = [CPTTextStyle textStyle]; 
     textStyle.color = [CPTColor blackColor]; 
     textStyle.fontSize = 16.0f; 
     textStyle.textAlignment = CPTTextAlignmentCenter; 
     barGraph.titleTextStyle = textStyle; 
     barGraph.titleDisplacement = CGPointMake(0.0f, -10.0f); 
     barGraph.titlePlotAreaFrameAnchor = CPTRectAnchorTop; 


     CPTXYAxisSet *axisSet = (CPTXYAxisSet *)barGraph.axisSet; 
     CPTXYAxis *x = axisSet.xAxis; 
     // x.axisLineStyle = nil; 
     // x.majorTickLineStyle = nil; 
     // x.minorTickLineStyle = nil; 
     x.majorIntervalLength = CPTDecimalFromString(@"70"); 
     x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0"); 
     x.title = @"Names"; 
     x.titleLocation = CPTDecimalFromFloat(7.5f); 
     x.titleOffset = 50.0f; //25.0f; 
     x.labelRotation = M_PI/5; 
     x.labelingPolicy = CPTAxisLabelingPolicyNone; 


     NSArray *customTickLocations = [NSArray arrayWithObjects: [NSDecimalNumber numberWithInt:1], [NSDecimalNumber numberWithInt: 5], [NSDecimalNumber numberWithInt:9], [NSDecimalNumber numberWithInt:13], nil]; 


     // NSArray *xAxisLabels = [NSArray arrayWithObjects:@"Smoke", @"Nicotine", @"Tar", @"", nil]; 
     // NSUInteger labelLocation = 0; 
     //  
     // NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]]; 
     // for (NSNumber *tickLocation in customTickLocations) 
     // { 
     //  CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle]; 
     //  newLabel.tickLocation = [tickLocation decimalValue]; 
     //  newLabel.offset = x.labelOffset + x.majorTickLength; 
     //  newLabel.rotation = M_PI/xAxisLength; 
     //  [customLabels addObject:newLabel]; 
     //  [newLabel release]; 
     // } 
     //  
     // x.axisLabels = [NSSet setWithArray:customLabels]; 

     CPTXYAxis *y = axisSet.yAxis; 
     // y.axisLineStyle = nil; 
     // y.majorTickLineStyle = nil; 
     // y.minorTickLineStyle = nil; 
     y.majorIntervalLength = CPTDecimalFromString(@"100"); 
     y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0"); 
     // y.title = @"Work Status"; 
     // y.titleOffset = 40.0f; 
     // y.titleLocation = CPTDecimalFromFloat(150.0f); 


     CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) barGraph.defaultPlotSpace; 
     plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0f) length:CPTDecimalFromDouble(15.0f)]; 
     plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0f) length:CPTDecimalFromDouble(1000.0f)]; 

     CPTBarPlot *barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor blueColor] horizontalBars:NO]; 
     barPlot.plotRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0) length:CPTDecimalFromDouble(13)];//xAxisLength 
     barPlot.barOffset = CPTDecimalFromFloat(1.0f); 
     barPlot.baseValue = CPTDecimalFromString(@"0"); 
     barPlot.barWidth = CPTDecimalFromFloat(3.0f); 
     barPlot.cornerRadius = 2.0f; 
     barPlot.dataSource = self; 
     [barGraph addPlot:barPlot]; 

     [self.view addSubview:hostingView]; 
} 

enter image description here

+0

http://stackoverflow.com/questions/3905980/how-to-scale-graph-to-fit-to-visible-space?rq=1 –

回答

1

只是嘗試這種方式,可以幫助你:

CPTGraphHostingView *hostingView = [[CPTGraphHostingView alloc] initWithFrame:CGRectMake(10, 70, 768, 1004)]; 
    hostingView.tag=1; 
    [self.view addSubview:hostingView]; 
// [hostingView addSubview:OptionBtn]; 
    barChart = [[CPXYGraph alloc] initWithFrame:self.view.bounds]; 
    //barChart.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"FinalGraph.png"]]; 
    hostingView.hostedGraph = barChart; 
+0

感謝您的回覆 – SampathKumar

+0

如果我的答案幫助你,然後說tnx。 –

+0

我試過,但有些錯誤發現未知類型CPGraphHostingView – SampathKumar