当用户触摸绘图符号时,我尝试添加绘图符号的标签。 如何改变这个情节符号的颜色。 在这里,我的代码添加了情节符号的标签
- (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];
}
答案 0 :(得分:1)
在数据源中实现-symbolForScatterPlot:recordIndex:
方法。返回您想要具有特殊外观的每个索引的绘图符号,或者nil
在该索引处绘制标准绘图符号(plotSymbol
属性)。无论何时需要更新绘图符号,都要在绘图上调用-reloadData
。