Change line style of CPScatterPlot for different points

孤街浪徒 提交于 2019-12-24 08:22:24

问题


I'm using coreplot on ios and have a scatterplot. Is it possible to vary the line style depending on the point being plotted? I've only found how to set it for the whole plot.


回答1:


Yes. Make sure your graph delegate conforms to CPScatterPlotDelegate by implementing -symbolForScatterPlot:recordIndex:. Here's a working implementation which returns a different symbol for the index which matches _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;
}


来源:https://stackoverflow.com/questions/6479350/change-line-style-of-cpscatterplot-for-different-points

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