代码之家  ›  专栏  ›  技术社区  ›  Luc

iPhone:在我的核心绘图图上看不到任何标签

  •  0
  • Luc  · 技术社区  · 14 年前

    我正在用核心图构建一个图,除了在x轴和y轴上看不到任何标签外,它工作得很好。我只能看到主刻度和次刻度,但旁边没有值。一定有什么东西我错过了,但我不知道是什么。此外,是否可以为每个轴添加标签,例如:x(小时)、y(值)。

    我正在处理的图形是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");
    

    谢谢, 卢克

    1 回复  |  直到 14 年前
        1
  •  0
  •   Luc    14 年前

    好的,这是因为有太多的标签要显示,也因为轴在负片区域走得不够远=>没有地方显示标签。但是,graph.name不显示图形的名称。。。