ios - Core-Plot CPT 散点图数据标签

标签 ios core-plot

当您创建散点图时,它会自动标记图表上的点。我觉得这很烦人,想关闭它,因为它对我们正在做的事情没有用。有没有办法不删除所有标签?

明确地说,这些显示时没有添加任何注释。我想删除此默认行为。

enter image description here

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

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

    -(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"];
}

所以有些东西是默认打开的..

感谢所有帮助。

-大卫

最佳答案

您还可以通过以下方式使其显示在图表上:

    -(void)scatterPlot:(CPTScatterPlot *)plot
plotSymbolWasSelectedAtRecordIndex:(NSUInteger)index
{
    int plotNumber = 0;

    for (int i = 0; i < [mainDataForPlot count]; i++)
    {
        if ([mainDataForPlot objectAtIndex:i] != [NSNull null]
            &&
            [(NSString *)plot.identifier isEqualToString:
             [NSString stringWithFormat:@"%@-%@",[[mainDataForPlot objectAtIndex:i] objectAtIndex:0],[[mainDataForPlot objectAtIndex:i] objectAtIndex:1]]
             ]) 
        {
            plotNumber = i;
            break;
        }
    }

    if (self.symbolTextAnnotation != nil) 
    {
        self.symbolTextAnnotation = nil;
    }

    // Setup a style for the annotation
    CPTMutableTextStyle *hitAnnotationTextStyle = [CPTMutableTextStyle textStyle];
    hitAnnotationTextStyle.color = [CPTColor whiteColor];
    hitAnnotationTextStyle.fontSize = 16.0f;
    hitAnnotationTextStyle.fontName = @"Helvetica-Bold";

    // Determine point of symbol in plot coordinates
    NSNumber *x = [NSNumber numberWithInt:index];
    NSNumber *y = [[[mainDataForPlot objectAtIndex:plotNumber] objectAtIndex:3] objectAtIndex:index];
    NSArray *anchorPoint = [NSArray arrayWithObjects:x, y, nil];

    // Add annotation
    // First make a string for the y value
    NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init] autorelease];
    [formatter setMaximumFractionDigits:2];
    NSString *yString = [formatter stringFromNumber:y];

    // Now add the annotation to the plot area
    CPTTextLayer *textLayer = [[[CPTTextLayer alloc] initWithText:yString style:hitAnnotationTextStyle] autorelease];
    self.symbolTextAnnotation = [[[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:(CPTXYPlotSpace *)self.graph.defaultPlotSpace  anchorPlotPoint:anchorPoint] autorelease];
    self.symbolTextAnnotation.contentLayer = textLayer;
    self.symbolTextAnnotation.displacement = CGPointMake(0.0f, 20.0f);
    [graph.plotAreaFrame.plotArea addAnnotation:symbolTextAnnotation];

}

关于ios - Core-Plot CPT 散点图数据标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14915558/

相关文章:

ios - 在 iOS 10.3 及更高版本中,是否可以设置备用图标名称并将其用于应用程序包/二进制文件之外的图像?

ios - GraphQL Apollo iOS 客户端响应 header

iphone - 在 NSString 中查找子字符串的所有位置(不仅仅是第一个)

ios - 以模态方式呈现的 ViewController 能否使用 NavigationController 的工具栏

iphone - CALayer 的抗锯齿对角线边缘

ios - UIScrollView 内的 CPTXYGraph

iphone - 在核心图中配置轴

ios - 核心图 - 使图形全屏显示的选项 - 呈现模态问题后添加 subview

objective-c - NSTimer 的 Core Plot 动画

ios - 如何使用 Coreplot 在 CPTLayerHostingView 中添加关闭按钮