Change color plot symbol at index - CorePlot

有些话、适合烂在心里 提交于 2019-12-12 05:54:55

问题


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

}


回答1:


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.



来源:https://stackoverflow.com/questions/13236871/change-color-plot-symbol-at-index-coreplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!