2009-11-17 67 views
2

我在這裏經歷了教程:http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application,我可以得到一個圖形顯示,但我沒有看到任何刻度線或標記在我的座標軸上。我忽略了一些簡單的東西嗎?下面是我創建圖的代碼,並且我還實現了委託功能。我看到軸和圖,但沒有軸刻度線或標籤。iPhone核心劇情刻度線標記不顯示

感謝您提供任何幫助。

- (void) showGraph { 

    graph = [[CPXYGraph alloc] initWithFrame: CGRectMake(0,0, 320, 320)]; 

    CPLayerHostingView *graphView = [[CPLayerHostingView alloc] initWithFrame:CGRectMake(0,0, 320, 320)]; 
    graphView.backgroundColor = [UIColor blueColor]; 

    AppDelegate *t = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
    [t.mapVC.view addSubview:graphView]; 

    graphView.hostedLayer = graph; 
    graph.paddingLeft = 20.0; 
    graph.paddingTop = 20.0; 
    graph.paddingRight = 20.0; 
    graph.paddingBottom = 20.0; 

    float minElevation = 0; 
    float maxElevation = 10; 
    float minTime = 0; 
    float maxTime = 5; 

    CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace; 
    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(minTime) 
               length:CPDecimalFromFloat(maxTime)]; 
    plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(minElevation) 
               length:CPDecimalFromFloat(maxElevation)]; 

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

    CPLineStyle *blackStyle = [CPLineStyle lineStyle]; 
    blackStyle.lineColor = [CPColor blackColor]; 
    blackStyle.lineWidth = 5.0f; 
    CPLineStyle *whiteStyle = [CPLineStyle lineStyle]; 
    whiteStyle.lineColor = [CPColor whiteColor]; 
    whiteStyle.lineWidth = 5.0f; 

    axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"]decimalValue]; 

    axisSet.xAxis.minorTicksPerInterval = 4; 
    axisSet.xAxis.majorTickLineStyle = whiteStyle; 
    axisSet.xAxis.minorTickLineStyle = whiteStyle; 
    axisSet.xAxis.axisLineStyle = blackStyle; 
    axisSet.xAxis.minorTickLength = 5.0f; 
    axisSet.xAxis.majorTickLength = 10.0f; 
    axisSet.xAxis.labelOffset = 3.0f; 

    axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"]decimalValue]; 
    axisSet.yAxis.minorTicksPerInterval = 4; 
    axisSet.yAxis.majorTickLineStyle = blackStyle; 
    axisSet.yAxis.minorTickLineStyle = blackStyle; 
    axisSet.yAxis.axisLineStyle = whiteStyle; 
    axisSet.yAxis.minorTickLength = 5.0f; 
    axisSet.yAxis.majorTickLength = 10.0f; 
    axisSet.yAxis.labelOffset = 3.0f; 

    CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc] 
            initWithFrame:graph.bounds] autorelease]; 
    xSquaredPlot.identifier = @"X Squared Plot"; 
    xSquaredPlot.dataLineStyle.lineWidth = 2.0f; 
    xSquaredPlot.dataLineStyle.lineColor = [CPColor greenColor]; 
    xSquaredPlot.dataSource = self; 
    [graph addPlot:xSquaredPlot]; 

    CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol]; 
    greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]]; 
    greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0); 

    xSquaredPlot.plotSymbol = greenCirclePlotSymbol; 
} 

回答

6

在軸的外側需要一些空間。 Core Plot還沒有爲你自動完成。

嘗試添加一些填充到graph.plotArea.plotGroupgraph.plotArea.axisSet。以iPhone測試應用程序中的條形圖爲例。

+0

是的,不幸的是,自該教程發佈以來,庫上的API已經發生了一些變化。我們嘗試維護示例應用程序以展示與庫進行交互的正確方式。 – 2009-11-18 11:47:16