我在ios上使用coreplot并有一个散点图。是否可以根据绘制的点来改变线型?我只发现了如何为整个情节设置它。

最佳答案

是。通过实现-CPScatterPlotDelegate来确保您的图形委托符合symbolForScatterPlot:recordIndex:。这是一个有效的实现,它为匹配_selectedIndex的索引返回一个不同的符号:

- (CPPlotSymbol *)symbolForScatterPlot:(CPScatterPlot *)plot recordIndex:(NSUInteger)index
{
    CPMutableLineStyle *symbolLineStyle = [CPMutableLineStyle lineStyle];
    symbolLineStyle.lineColor = [CPColor blackColor];
    CPPlotSymbol *plotSymbol = [CPPlotSymbol ellipsePlotSymbol];
    plotSymbol.lineStyle = symbolLineStyle;

    if (_selectedIndex != NSNotFound && index == _selectedIndex)
    {
        plotSymbol.symbolType = CPPlotSymbolTypeDiamond;
        plotSymbol.size = CGSizeMake(12, 12);
        plotSymbol.fill = [CPFill fillWithColor:[CPColor redColor]];
    }
    else
    {
        plotSymbol.symbolType = CPPlotSymbolTypeEllipse
        plotSymbol.size = CGSizeMake(8, 8);
        plotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
    }
    return plotSymbol;
}

10-08 03:06