更改CPScatterPlot不同点的线型 [英] Change line style of CPScatterPlot for different points

查看:122
本文介绍了更改CPScatterPlot不同点的线型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

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

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

这篇关于更改CPScatterPlot不同点的线型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆