iOS核心图 - 散点图符号颜色外观

时间:2014-02-08 03:41:58

标签: ios core-plot scatter-plot

我正在使用CorePlot进行散点图,并且想知道如何获得散点图的圆圈,其颜色效果与此处http://i.stack.imgur.com/7ZcqY.jpg一样 我希望获得CPTXYScatterPlot - Can I set the Z order of plot symbols?中的颜色。

1 个答案:

答案 0 :(得分:0)

symbolForScatterPlot实施中,使用渐变填充创建circlePlotSymbol,如下所示:

CPTPlotSymbol *circlePlotSymbol = [CPTPlotSymbol ellipsePlotSymbol];

// Obviously for a real bubble chart you'll want to get the color from somewhere so they're not all the same
CPTColor *endColor = [CPTColor redColor];
CPTColor *startColor = [endColor colorWithAlphaComponent:0.4f];
CPTGradient *gradient = [CPTGradient gradientWithBeginningColor:startColor endingColor:endColor];

然后将渐变类型设置为“径向”,并将渐变设置为plotSymbol上的填充。如果您希望它看起来像是从某个角度点亮,您可以将startAnchor设置为偏离中心的点:

gradient.gradientType = CPTGradientTypeRadial;
graphGradient.startAnchor = CGPointMake(0.35, 0.75);
circlePlotSymbol.fill = [CPTFill fillWithGradient:gradient];

如果您不想在圆圈周围设置边框,请将线条样式颜色设置为清除和/或将宽度设置为0.0f(可能不需要同时执行这两种操作):

CPTMutableLineStyle *lineStyle = [[CPTMutableLineStyle alloc] init];
lineStyle.lineColor = [CPTColor clearColor];
lineStyle.lineWidth = 0.0f;
circlePlotSymbol.lineStyle = lineStyle;
[lineStyle release];

设置气泡的大小:

// For a real bubble chart, you'll need to calculate this from your data
circlePlotSymbol.size = CGSizeMake(50.0f, 50.0f);

并返回你的情节符号:

return circlePlotSymbol;

应该这样做。我没有在我面前的代码,所以我要从内存中去(请原谅任何拼写错误或错误的语法,因为我现在也无法访问编译器),但希望这将关闭足以让你指向正确的方向。