2013-02-16 56 views
2

當您創建散點圖時,它會自動標記圖上的點。我覺得這很煩人,想關閉它,因爲它對我們正在做的事沒有用處。有沒有刪除所有標籤的方法?Core-Plot CPTScatterPlot數據標籤

要清楚,這些顯示沒有添加任何註釋..我想刪除此默認行爲。

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

因此,一些被默認開啓..

感謝任何及所有的幫助。

-David

+0

symbolTextAnnotation = nil – casillic 2013-02-17 00:37:33

+0

我在哪裏設置?我沒有設置任何東西,註釋等。 – 2013-02-17 06:17:03

回答

1

「數據標籤」(每個點上方的標籤),默認情況下不會出現。自動標籤需要labelTextStylelabelFormatter。這兩個屬性默認爲nil,這隱藏了標籤。

+0

那麼我把它設置爲零?在圖上?或情節? – 2013-02-17 22:41:50

+0

剛剛嘗試過:boundLinePlot.labelTextStyle = nil; boundLinePlot.labelFormatter = nil; 沒有變化。 – 2013-02-17 22:44:54

+1

你實現了哪些數據源方法? '-dataLabelForPlot:recordIndex:'顯然也會顯示數據標籤。 – 2013-02-17 23:23:25

5

你也可以讓它出現在圖形上,如果你通過觸摸:

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

} 
+0

你讀過這個問題嗎?我在問如何讓這些不出現。我沒有添加任何註釋。 – 2013-02-17 06:15:28

+0

大衛我明白你的問題。我指出他們可能來自哪裏,而不是如何添加它們。您應該至少發佈一些代碼,以便任何人都能夠進一步幫助您。祝你好運。 – casillic 2013-02-17 15:57:53

+0

這是相當整潔,casillic。謝謝! – jay492355 2013-06-14 18:50:00