2013-04-29 72 views
0

我正在使用核心圖庫來繪製3個不同視圖中的圖形。問題僅限於3個圖形中的第3個圖形顯示正確...但是,如果我單獨繪製每個圖形,然後他們總是顯示出來right..Any線索將是巨大的幫助.Thanks的無法使用核心圖在3個不同視圖中繪製3個圖形iOS

//In ViewWillAppear 

    -(void) viewWillAppear:(BOOL)animated 
{ 

    dataPoints  = [[NSMutableArray alloc]init]; 

    // Create graph from theme 
    CPTgraph1 = [(CPTXYGraph *)[CPTXYGraph alloc] initWithFrame:CGRectZero]; 
    CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme]; 
    [CPTgraph1 applyTheme:theme]; 

    CPTXYPlotSpace *plotSpace1; 
    plotSpace1= (CPTXYPlotSpace *)CPTgraph1.defaultPlotSpace; 

    CPTScatterPlot *dataSourceLinePlot1 = [(CPTScatterPlot *)[CPTScatterPlot alloc]  initWithFrame:CPTgraph1.bounds]; 

    CPTgraph2 = [(CPTXYGraph *)[CPTXYGraph alloc] initWithFrame:CGRectZero]; 
    //CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme]; 
    [CPTgraph2 applyTheme:theme]; 

    CPTXYPlotSpace *plotSpace2; 
    plotSpace2= (CPTXYPlotSpace *)CPTgraph2.defaultPlotSpace; 

    CPTScatterPlot *dataSourceLinePlot2 = [(CPTScatterPlot *)[CPTScatterPlot alloc] initWithFrame:CPTgraph2.bounds]; 

    CPTgraph3 = [(CPTXYGraph *)[CPTXYGraph alloc] initWithFrame:CGRectZero]; 
    //CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme]; 
    [CPTgraph3 applyTheme:theme]; 

    CPTXYPlotSpace *plotSpace3; 
    plotSpace3= (CPTXYPlotSpace *)CPTgraph3.defaultPlotSpace; 

    CPTScatterPlot *dataSourceLinePlot3 = [(CPTScatterPlot *)[CPTScatterPlot alloc] initWithFrame:CPTgraph3.bounds]; 

    [self plotGraph:graph1 withData:"SomeData" withGraph:CPTgraph1 withPlotSpace:plotSpace1 withCPTScatterPlot:dataSourceLinePlot1]; 

    [self plotGraph:graph2 withData:"Some Data" withGraph:CPTgraph2 withPlotSpace:plotSpace2 withCPTScatterPlot:dataSourceLinePlot2]; 

    [self plotGraph:graph3 withData:"Some Data" withGraph:CPTgraph3 withPlotSpace:plotSpace3 withCPTScatterPlot:dataSourceLinePlot3]; 

} 


-(void)plotGraph :(CPTGraphHostingView *)graphView withData:(NSMutableArray*)refData withGraph:(CPTXYGraph *) graph withPlotSpace:(CPTXYPlotSpace *) plotSpace withCPTScatterPlot:(CPTScatterPlot *)dataSourceLinePlot 


{ 

[self readFromData:refData]; 


graphView.hostedGraph = graph; 

graph.paddingLeft = 0.0; 
graph.paddingTop = 0.0; 
graph.paddingRight = 0.0; 
graph.paddingBottom = 0.0; 

graph.plotAreaFrame.paddingLeft = 10.0; 
graph.plotAreaFrame.paddingTop = 10.0; 
graph.plotAreaFrame.paddingRight = 10.0; 
graph.plotAreaFrame.paddingBottom = 10.0; 

graph.plotAreaFrame.plotArea.fill = graph.plotAreaFrame.fill; 
graph.plotAreaFrame.fill   = nil; 

graph.plotAreaFrame.borderLineStyle = nil; 
graph.plotAreaFrame.cornerRadius = 0.0; 


plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(minimumValueForXAxis) 
               length:CPTDecimalFromDouble(maximumValueForXAxis)]; 

    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(minimumValueForYAxis) 
               length:CPTDecimalFromDouble(ceil( (maximumValueForYAxis - minimumValueForYAxis)/majorIntervalLengthForY) * majorIntervalLengthForY)]; 



CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet; 

// Grid line styles 
CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle]; 
majorGridLineStyle.lineWidth = 0.75; 
majorGridLineStyle.lineColor = [[CPTColor colorWithGenericGray:0.2] colorWithAlphaComponent:0.75]; 

CPTMutableLineStyle *minorGridLineStyle = [CPTMutableLineStyle lineStyle]; 
minorGridLineStyle.lineWidth = 0.25; 
minorGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:0.1]; 

CPTXYAxis *x = axisSet.xAxis; 
x.minorTicksPerInterval = 9; 
x.majorIntervalLength = CPTDecimalFromDouble(majorIntervalLengthForX); 
x.labelOffset   = 5.0; 


x.axisConstraints  = [CPTConstraints constraintWithLowerOffset:0.0]; 

CPTXYAxis *y = axisSet.yAxis; 
y.minorTicksPerInterval = 9; 
y.majorIntervalLength = CPTDecimalFromDouble(majorIntervalLengthForY); 
y.labelOffset   = 5.0; 
y.majorGridLineStyle = majorGridLineStyle; 
y.minorGridLineStyle = minorGridLineStyle; 

y.axisConstraints  = [CPTConstraints constraintWithLowerOffset:0.0]; 

dataSourceLinePlot.identifier = @"Data Source Plot"; 

CPTMutableLineStyle *lineStyle = [dataSourceLinePlot.dataLineStyle mutableCopy]; 
lineStyle.lineWidth    = 1.0; 
lineStyle.lineColor = [CPTColor orangeColor]; 
dataSourceLinePlot.dataLineStyle = lineStyle; 

dataSourceLinePlot.dataSource = self; 
[graph addPlot:dataSourceLinePlot toPlotSpace:plotSpace]; 


} 

方法readFromData將只計算X,Y值,並將其存儲在數據點陣列。

只是闡述多一點...圖並展示了在第一和第二的觀點,但似乎超出範圍的原因,我只能看到它的一部分...但第三曲線獲取顯示correctly..i猜測它有是與範圍或軸..

plot

+0

你可以發佈當你試圖顯示所有3時會發生什麼的屏幕截圖嗎? – 2013-04-29 14:10:17

+0

一會兒 – 2013-04-29 14:12:07

+0

@andrewlattis張貼圖片我補充說,看起來像圖被完全加載的截圖 – 2013-04-29 14:25:45

回答

1

所有三個地塊使用相同的情節對範圍內的劇情空間。你的繪圖數據是否適合該範圍?如果不是,則需要爲每個圖計算不同的繪圖範圍。