Core-Plot CPTScatterPlot数据标签 [英] Core-Plot CPTScatterPlot data labels

查看:143
本文介绍了Core-Plot CPTScatterPlot数据标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建散点图时,它会自动标记图表本身上的点。我发现这非常烦人,并希望将其关闭,因为它对我们正在做的事情没有用。有没有办法没有删除所有标签?

When you create a scatter plot it auto-labels the points on the graph itself. I find this very annoying and want to shut it off as it isn't useful for what we are doing. Is there a way without removing all labels?

要清除,这些显示没有添加任何注释..我想删除此默认行为。

TO BE CLEAR, these show up without adding any annotations.. I want to remove this default behavior.

我想删除图中的1,2,3,4,5,6,7等。

I want to remove the 1, 2, 3, 4, 5, 6, 7 etc in the graph.

这是我的代码用于创建图形。如您所见,它没有设置任何注释等。

Here is the code I'm using to create the graph. As you can see it doesn't set any annotations, etc.

    -(void) constructScatterPlot
    {
    // Create graph from theme
    graph = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
    CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
    [graph applyTheme:theme];
    scatterPlotView.hostedGraph = graph;

    graph.paddingLeft   = 0.0;
    graph.paddingTop    = 0.0;
    graph.paddingRight  = 0.0;
    graph.paddingBottom = 0.0

    // Setup plot space
    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
    plotSpace.allowsUserInteraction = NO;
    plotSpace.xRange                = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-2.5) length:CPTDecimalFromFloat(28)];
    plotSpace.yRange                = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-5) length:CPTDecimalFromFloat(desiredPeak+10)];

    NSArray *exclusionRanges = [NSArray arrayWithObjects:[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-1) length:CPTDecimalFromFloat(-100)],
                                                         [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(25) length:CPTDecimalFromFloat(10000)], nil];

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

    CPTXYAxis *x          = axisSet.xAxis;
    x.majorIntervalLength         = CPTDecimalFromString(@"4");
    x.minorTicksPerInterval = 4;
    x.minorTickLength = 5.0f;
    x.majorTickLength = 7.0f;
    x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
    x.minorTicksPerInterval       = 10;
    x.labelExclusionRanges = exclusionRanges;

    exclusionRanges = [NSArray arrayWithObjects:[CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-1) length:CPTDecimalFromFloat(-100)],
                                                [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(101) length:CPTDecimalFromFloat(10000)], nil];
    CPTXYAxis *y = axisSet.yAxis;
    y.majorIntervalLength         = CPTDecimalFromString(@"10");
    y.minorTicksPerInterval       = 20;
    y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
    y.labelExclusionRanges = exclusionRanges;

    // Put an area gradient under the plot above
    CPTColor *areaColor       = [CPTColor colorWithComponentRed:0.3 green:1.0 blue:0.3 alpha:0.8];
    CPTGradient *areaGradient = [CPTGradient gradientWithBeginningColor:areaColor endingColor:[CPTColor clearColor]];
    areaGradient.angle = -90.0f;
    CPTFill *areaGradientFill = [CPTFill fillWithGradient:areaGradient];

    // Create a blue plot area
    CPTScatterPlot *boundLinePlot = [[CPTScatterPlot alloc] init];
    boundLinePlot.identifier = @"Blue Plot";

    CPTMutableLineStyle *lineStyle = [boundLinePlot.dataLineStyle mutableCopy];
    //lineStyle.miterLimit = 1.0f;
    lineStyle.lineWidth  = 3.0f;
    lineStyle.lineColor  = [CPTColor blueColor];
    lineStyle.dashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:5.0f], [NSNumber numberWithFloat:5.0f], nil];
    boundLinePlot.dataSource     = self;
    boundLinePlot.cachePrecision = CPTPlotCachePrecisionDecimal;//Double;
    boundLinePlot.interpolation  = CPTScatterPlotInterpolationCurved;//Histogram;
    [graph addPlot:boundLinePlot];

    // Do a blue gradient
    CPTColor *areaColor1       = [CPTColor colorWithComponentRed:0.3 green:0.3 blue:1.0 alpha:0.8];
    CPTGradient *areaGradient1 = [CPTGradient gradientWithBeginningColor:areaColor1 endingColor:[CPTColor clearColor]];
    areaGradient1.angle         = -90.0f;
    areaGradientFill            = [CPTFill fillWithGradient:areaGradient1];
    boundLinePlot.areaFill      = areaGradientFill;
    boundLinePlot.areaBaseValue = [[NSDecimalNumber zero] decimalValue];

    CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    fadeInAnimation.duration            = 1.0f;
    fadeInAnimation.removedOnCompletion = NO;
    fadeInAnimation.fillMode            = kCAFillModeForwards;
    fadeInAnimation.toValue             = [NSNumber numberWithFloat:1.0];
    [boundLinePlot addAnimation:fadeInAnimation forKey:@"animateOpacity"];
}

默认情况下会启用某些内容..

So something is turned on by default..

感谢您提供任何帮助。

-David

推荐答案

默认情况下不显示数据标签(每个点上方的标签)。自动标签需要 labelTextStyle labelFormatter 。这两个属性都默认为 nil ,它会隐藏标签。

"Data labels" (labels above each point) do not appear by default. The automatic labels require both a labelTextStyle and labelFormatter. Both of these properties default to nil which hides the labels.

这篇关于Core-Plot CPTScatterPlot数据标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆