当两个图显示在同一图表中时,如何将散点图放在条形图前面

时间:2012-10-07 19:44:36

标签: ios ipad core-plot

我在IOS上使用coreplot。我在同一图表中显示散点图和条形图。当它们显示时,条形图位于屏幕的顶部,因此我无法真正看到背后的散点图。我想将散点图放在前景中。

我该怎么做?

见下面的代码。任何帮助将不胜感激

    // Create barChart from theme
barChart = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme]; //  
[barChart applyTheme:theme];

theHostingView.hostedGraph = barChart;

// Border
barChart.plotAreaFrame.borderLineStyle = nil;
barChart.plotAreaFrame.cornerRadius    = 0.0f;

// Paddings
barChart.paddingLeft   = 0.0f;
barChart.paddingRight  = 0.0f;
barChart.paddingTop    = 0.0f;
barChart.paddingBottom = 0.0f;

// Offset pour placer les coordoonees du graph
barChart.plotAreaFrame.paddingLeft   = 70.0;
barChart.plotAreaFrame.paddingTop    = 20.0;
barChart.plotAreaFrame.paddingRight  = 15.0;
barChart.plotAreaFrame.paddingBottom = 35.0;

// Graph title
[self configureTitle];


// Add plot space for horizontal bar charts
_plotSpace = (CPTXYPlotSpace *)barChart.defaultPlotSpace;

float minAxis = 0.0;
if ([_theKPI.unit isEqualToString:@"%"]) {
    float intervalSize = ((_maxValue - minAxis)/100.0)/4;

    minAxis = _minValue - intervalSize;
    if (minAxis <= 0) {
        minAxis = 0.0;
    }

    _plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(minAxis/100.0) length:CPTDecimalFromFloat((_maxValue - minAxis)/100.0)];

} else {

    if (_minValue >= 0) {
        _plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat(_maxValue)];
    } else {
        _plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat(_minValue)];
    }
}


CPTXYAxis* xAxis = [[CPTXYAxis alloc] initWithFrame:CGRectZero];
CPTXYAxis* yAxis = [[CPTXYAxis alloc] initWithFrame:CGRectZero];
xAxis.plotSpace = _plotSpace;
yAxis.plotSpace = _plotSpace;

[self configureXAxis:xAxis min:minAxis plotSpace:_plotSpace];
[self configureYAxis:yAxis min:minAxis];


CPTXYPlotSpace* secondPlotSpace = [[CPTXYPlotSpace alloc] init];
secondPlotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat(50.0)];
[self configurePlotSpace:secondPlotSpace];


[barChart addPlotSpace:secondPlotSpace];

CPTXYAxis* yRightAxis = [[CPTXYAxis alloc] initWithFrame:CGRectZero];
yRightAxis.plotSpace = secondPlotSpace;
[self configureYRightAxis:yRightAxis];

barChart.axisSet.axes = [NSArray arrayWithObjects:xAxis, yAxis, yRightAxis, nil];

// Configure the Scatter Plot
_plot = [[CPTScatterPlot alloc] init];
_plot.dataSource = self;
_plot.identifier = @"mainplot";

CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.lineColor = [CPTColor whiteColor];
lineStyle.lineWidth = 3.0f;
_plot.dataLineStyle = lineStyle;

CPTPlotSymbol* greenCirclePlotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
greenCirclePlotSymbol.fill = [CPTFill fillWithColor:[CPTColor blueColor]];
greenCirclePlotSymbol.size = CGSizeMake(5.0, 5.0);
_plot.plotSymbol = greenCirclePlotSymbol;


// Configure the Bar Plot
_barPlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor blueColor] horizontalBars:NO];
_barPlot.baseValue  = CPTDecimalFromString(@"0");
_barPlot.dataSource = self;
_barPlot.delegate = self;
_barPlot.barOffset  = CPTDecimalFromFloat(-0.25f);
_barPlot.identifier = @"Bar Plot 1";


[barChart addPlot:_plot toPlotSpace:secondPlotSpace];
[barChart addPlot:_barPlot];

的Seb。

1 个答案:

答案 0 :(得分:0)

添加到图表中的最后一个图表将显示在前面:

[barChart addPlot:_barPlot];
[barChart addPlot:_plot toPlotSpace:secondPlotSpace];