2010-06-16 61 views
0

我正在构建一个带有核心阴谋的图,除了我在x和y轴上看不到任何标签之外,工作正常。我只能看到主要和次要的蜱虫,但它们旁边没有任何值。必须有我失踪的东西,但我不知道是什么。另外,是否可以为每个轴添加标签,例如:x(小时),y(值)。iPhone:看不到我的核心阴谋图上的任何标签

我正在处理的图是listview的第一行的一部分。

的代码是:

  NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"GraphCustomViewCell" owner:nil options:nil]; 

      for(id currentObject in topLevelObjects) 
      { 
       if([currentObject isKindOfClass:[GraphCustomViewCell class]]) 
       { 
        cell = (GraphCustomViewCell *)currentObject; 
        break; 
       } 
      } 

      CGRect frame = cell.contentView.bounds; 

      CPLayerHostingView *hostingView = [[CPLayerHostingView alloc] initWithFrame: frame]; 
      [cell addSubview:hostingView]; 

      // Create graph 
      CPTheme *theme = [CPTheme themeNamed:kCPPlainWhiteTheme]; 
      graph = (CPXYGraph *)[theme newGraph]; 

      // Add graph to view 
      hostingView.hostedLayer = graph; 
      graph.paddingLeft = 50.0; 
      graph.paddingTop = 5.0; 
      graph.paddingRight = 5.0; 
      graph.paddingBottom = 25.0; 

      // Adjust graph 
      float xmax = [[[self arrayFromData] objectForKey:@"data"] count]; 
      CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace; 
      plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0) 
                  length:CPDecimalFromFloat(xmax)]; 
      plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0) 
                  length:CPDecimalFromFloat(3000)]; 

      CPTextStyle *blackText = [[CPTextStyle textStyle] color:[CPColor blackColor]]; 
      CPLineStyle *lineStyle = [CPLineStyle lineStyle]; 
      lineStyle.lineColor = [CPColor blackColor]; 
      lineStyle.lineWidth = 1.0f; 

      axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue]; 
      axisSet.xAxis.minorTicksPerInterval = 4; 
      axisSet.xAxis.majorTickLineStyle = lineStyle; 
      axisSet.xAxis.minorTickLineStyle = lineStyle; 
      axisSet.xAxis.axisLineStyle = lineStyle; 
      axisSet.xAxis.minorTickLength = 4.0f; 
      axisSet.xAxis.majorTickLength = 8.0f; 
      axisSet.xAxis.labelOffset = 3.0f; 
      axisSet.xAxis.labelTextStyle = blackText; 


      axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"500"] decimalValue]; 
      axisSet.yAxis.minorTicksPerInterval = 4; 
      axisSet.yAxis.majorTickLineStyle = lineStyle; 
      axisSet.yAxis.minorTickLineStyle = lineStyle; 
      axisSet.yAxis.axisLineStyle = lineStyle; 
      axisSet.yAxis.minorTickLength = 4.0f; 
      axisSet.yAxis.majorTickLength = 8.0f; 
      axisSet.yAxis.labelOffset = 1.0f; 

      CPScatterPlot *dataSourceLinePlot = [[[CPScatterPlot alloc] init] autorelease]; 
      dataSourceLinePlot.identifier = @"MyGraph"; 
      dataSourceLinePlot.dataLineStyle.lineWidth = 1.f; 
      dataSourceLinePlot.dataLineStyle.lineColor = [CPColor greenColor]; 
      dataSourceLinePlot.dataSource = self; 
      [graph addPlot:dataSourceLinePlot]; 

      // Put an area gradient under the plot above 
      CPColor *areaColor = [CPColor colorWithComponentRed:0.3 
                  green:1.0 
                  blue:0.3 
                  alpha:0.3]; 
      CPGradient *areaGradient = [CPGradient gradientWithBeginningColor:areaColor 
                    endingColor:[CPColor clearColor]]; 
      areaGradient.angle = -90.0f; 
      CPFill *areaGradientFill = [CPFill fillWithGradient:areaGradient]; 
      dataSourceLinePlot.areaFill = areaGradientFill; 
      dataSourceLinePlot.areaBaseValue = CPDecimalFromString(@"1.75"); 

非常感谢, 问候, 吕克

PS:快速编辑,我曾与graph.name = “我的图” 检查,但不会显示任何内容在图上

回答

0

好的,这是因为有太多的标签要显示,并且还因为轴在负面区域没有足够的长度=>没有地方显示标签。但是,graph.name不显示图的名称...