2011-11-01 83 views
2

我正在爲我的iOS應用程序的圖形時,使用Core Plot library數軸上使用核心情節

但是我的軸不顯示任何數字或標籤不顯示:

Screenshot of graph

這裏是我的viewDidLoad方法:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    //[self generateExponentialDataSamples]; 
    [self generateGraphDataSamples]; 

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

    // Create graph from theme 
    CPTXYGraph *graph = [[CPTXYGraph alloc] initWithFrame:self.view.bounds]; 
    CPTTheme *theme = [CPTTheme themeNamed:kCPTPlainWhiteTheme]; 
    [graph applyTheme:theme]; 
    graph.paddingLeft = 30.0; 
    graph.paddingTop = 30.0; 
    graph.paddingRight = 30.0; 
    graph.paddingBottom = 30.0;    

    hostingView.hostedGraph = graph; 

    // Title 
    CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle]; 
    textStyle.color = [CPTColor greenColor]; 
    textStyle.fontSize = 18.0f; 
    textStyle.fontName = @"Helvetica"; 
    graph.title = @"My Progress"; 
    graph.titleTextStyle = textStyle; 
    graph.titleDisplacement = CGPointMake(0.0f, -20.0f); 

    double xAxisStart = 0.0; 
    double xAxisLength = MAX_X_VALUE; 
    double yAxisStart = 0.0; 
    //double yAxisLength = [[samples valueForKeyPath:@"@max.Y_VAL"]doubleValue]; 
    double yAxisLength = 10; 

    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace; 
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(xAxisStart) length:CPTDecimalFromDouble(xAxisLength)]; 
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(yAxisStart) length:CPTDecimalFromDouble(yAxisLength)]; 

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

    CPTXYAxis *x = axisSet.xAxis; 
    x.minorTicksPerInterval = 0; //the number of minor ticks between every major tick 
    x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0"); // The axis should begin in the origin 
    x.labelingPolicy = CPTAxisLabelingPolicyAutomatic; 
    x.title = @"x-axis"; 
    x.titleTextStyle = textStyle; 

    CPTXYAxis *y = axisSet.yAxis; 
    y.minorTicksPerInterval = 0; 
    y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0"); 
    y.labelingPolicy = CPTAxisLabelingPolicyAutomatic; 
    y.title = @"y-axis"; 
    y.titleTextStyle = textStyle; 

    CPTScatterPlot *dataSourceLinePlot = [[CPTScatterPlot alloc]init]; 
    dataSourceLinePlot.dataSource = self; 

    // Add line style 
    CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle]; 
    lineStyle.lineWidth = 1.0f; 
    lineStyle.lineColor = [CPTColor greenColor]; 
    dataSourceLinePlot.dataLineStyle = lineStyle; 

    // create the fill area 
    dataSourceLinePlot.areaFill = [CPTFill fillWithColor:[[CPTColor greenColor] colorWithAlphaComponent:0.2f]]; 
    dataSourceLinePlot.areaBaseValue = CPTDecimalFromString(@"0"); 

    [graph addPlot:dataSourceLinePlot]; 
} 

這是一個有點亂,但是我真的很感激一些幫助。

+0

感謝張貼的形象!我的聲譽不夠高。 :) –

回答

2

設置刻度方向各軸:

x.tickDirection = CPTSignPositive; 
y.tickDirection = CPTSignPositive; 
+0

非常感謝!它像一個魅力。但是你碰巧知道我怎樣才能得到圖表下方的數字? –

+0

在繪圖區框架上設置一些填充。在Plot Gallery應用程序中有幾個有用的示例。 –