1

目前我正在开发一个 iPad 应用程序,我正在使用 Core-Plot 在我的 iPhone 应用程序中开发条形图,然后我修改了 iPad 的框架大小以在 iPad 应用程序中导入相同的东西,但是条形图显示得很小在屏幕上,但我想在 iPad 上全屏显示,如何解决?请帮我

提前致谢

我试过这个

苹果手机

-(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];
}

在此处输入图像描述

4

1 回答 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;
于 2012-09-10T11:03:32.290 回答