本文介绍了更改索引处的颜色图符号-CorePlot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我尝试在用户触摸绘图符号时添加绘图符号的标签。
如何也更改此绘图符号的颜色。
这是我的代码,用于添加绘图符号的标签

I try add label of plot symbol when user touch at plot symbol.How to change color this plot symbol,too.Here i my code to add label of plot symbol

    - (void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex (NSUInteger)index {

if(symbolTextAnnotation) {
    [graph.plotAreaFrame.plotArea removeAnnotation:symbolTextAnnotation];
    [symbolTextAnnotation release];
    symbolTextAnnotation = nil;
}
if ([(NSString *)plot.identifier isEqualToString:@"TOTAL"]) {

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

    // Determine point of symbol in plot coordinates
    NSNumber *x          = [[plotData objectAtIndex:index] valueForKey:@"x"];
    NSNumber *y          = [[plotData objectAtIndex:index] valueForKey:@"y"];
    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:[[currencySymbol objectAtIndex:index] stringByAppendingFormat: yString] style:hitAnnotationTextStyle] autorelease];
    symbolTextAnnotation              = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:graph.defaultPlotSpace anchorPlotPoint:anchorPoint];
    symbolTextAnnotation.contentLayer = textLayer;
    symbolTextAnnotation.displacement = CGPointMake(0.0f, 20.0f);

    [graph.plotAreaFrame.plotArea addAnnotation:symbolTextAnnotation];

}

推荐答案

在数据源中实施 -symbolForScatterPlot:recordIndex:方法。为每个要有特殊外观的索引返回一个绘图符号,或者为 nil 返回以绘制标准绘图符号( plotSymbol 属性)。每当需要更新图解符号时,在图解上调用 -reloadData

Implement the -symbolForScatterPlot:recordIndex: method in your datasource. Return a plot symbol for each index that you want to have a special appearance or nil to draw the standard plot symbol (the plotSymbol property) at that index. Call -reloadData on the plot whenever you need to update the plot symbols.

这篇关于更改索引处的颜色图符号-CorePlot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 08:58