颠倒的x轴

时间:2011-08-09 06:00:37

标签: core-plot bar-chart

我正在使用coreplot创建条形图.Bar-chart正在显示但是它上下颠倒.X轴从屏幕顶部开始而不是在屏幕的底部......甚至是X-轴是不可见的。看起来图表中的条形图是悬挂的:( ....如何更改其位置并使其正确,甚至使x轴可见?

这是我的代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    [self generateDataSamples];

    double xAxisStart = 0;
    double xAxisLength = 14;

    double yAxisStart = 0;
//  double yAxisLength = [[samples valueForKeyPath:@"@max.Y_VAL"] doubleValue];
    double yAxisLength = 190.0;


    CPGraphHostingView *hostingView = [[CPGraphHostingView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:hostingView];

    CPXYGraph *graph = [[CPXYGraph alloc] initWithFrame:self.view.bounds];
    hostingView.hostedGraph = graph;


    CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(xAxisStart)
                                                   length:CPDecimalFromDouble(xAxisLength+1)];

    plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(yAxisStart)
                                                   length:CPDecimalFromDouble(yAxisLength+3)];

    CPBarPlot *plot = [[CPBarPlot alloc] initWithFrame:CGRectZero];
    plot.plotRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(0.0)
                                                 length:CPDecimalFromDouble(xAxisLength-5)];
    plot.barOffset = CPDecimalFromDouble(1.5);
    plot.dataSource = self;


    [graph addPlot:plot];
    [plot release];
    [graph release];
    [hostingView release];
}

谢谢你

1 个答案:

答案 0 :(得分:0)

在绘图区域框架中添加一些填充以使轴可见:

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

我不确定为什么图表会颠倒过来。托管视图的超级视图是否应用了任何转换?