问题
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