【问题标题】:Core-Plot Select a pointCore-Plot 选择一个点
【发布时间】:2015-02-02 03:23:19
【问题描述】:

我已经成功选择了一个点,但是我希望在这个点选择的时候,把颜色设置为和其他点不同的点来区分,如何实现,非常感谢

如何设置只有这个红色。

-(void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)index{ CPTXYGraph graph = (CPTXYGraph)_graph;

if ( _symbolTextAnnotation ){
    [graph.plotAreaFrame.plotArea removeAnnotation:_symbolTextAnnotation];
    _symbolTextAnnotation = nil;
}

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

// Determine point of symbol in plot coordinates
NSDictionary *dataPoint = _plotData[index];

NSNumber *x = dataPoint[@"x"];
NSNumber *y = dataPoint[@"y"];

NSArray *anchorPoint = @[x, y];

float yValue = [y floatValue];

NSString *yString = [NSString stringWithFormat:@"%.1f",yValue];

CPTTextLayer *textLayer = [[CPTTextLayer alloc] initWithText:yString style:hitAnnotationTextStyle];
CPTImage *background    = [CPTImage imageWithCGImage:[UIImage imageNamed:@"bg_red"].CGImage];
textLayer.fill          = [CPTFill fillWithImage:background];
textLayer.paddingLeft   = 2.0;
textLayer.paddingTop    = 2.0;
textLayer.paddingRight  = 2.0;
textLayer.paddingBottom = 2.0;

self.symbolTextAnnotation                    = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:graph.defaultPlotSpace anchorPlotPoint:anchorPoint];
_symbolTextAnnotation.contentLayer       = textLayer;
_symbolTextAnnotation.contentAnchorPoint = CGPointMake(0.5, 0.0);
_symbolTextAnnotation.displacement       = CGPointMake(0.0, 10.0);
[graph.plotAreaFrame.plotArea addAnnotation:_symbolTextAnnotation];

}

【问题讨论】:

  • Eric,谢谢,我已经按照提示解决了问题

标签: ios objective-c charts core-plot


【解决方案1】:

实现-symbolForScatterPlot:recordIndex: 数据源方法。返回nil 以使用默认的plotSymbol[NSNull null] 以不显示符号,或返回CPTPlotSymbol 以在给定数据索引处显示该符号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多