2011-11-01 108 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应用程序中有几个有用的示例。 –