【问题标题】:Change color plot symbol at index - CorePlot更改索引处的颜色绘图符号 - CorePlot
【发布时间】:2012-11-05 17:06:31
【问题描述】:

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

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

}

【问题讨论】:

    标签: ios5 core-plot


    【解决方案1】:

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

    【讨论】:

    • 你能告诉我更多细节吗?我试过了,绘制图形时所有的线图都会改变颜色:(
    • 检查绘图参数。使用它来决定是否返回自定义符号。每个地块都有一个identifier 属性,您可以使用它来唯一地标识地块。
    猜你喜欢
    • 2012-12-17
    • 1970-01-01
    • 2017-01-20
    • 1970-01-01
    • 1970-01-01
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多