iOS Core Plot - Scatter plot symbol color appearance

China☆狼群 提交于 2020-01-17 01:42:04

问题


I am using CorePlot for Scatter plot and would like to know how to obtain the circles of the scatter plot with such a color effect as it is here http://i.stack.imgur.com/7ZcqY.jpg I would like to get the color as in CPTXYScatterPlot - Can I set the Z order of plot symbols?.


回答1:


In your symbolForScatterPlot implementation, create a circlePlotSymbol with a gradient fill, like so:

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

Then set the gradient type to Radial, and set your gradient as the fill on your plotSymbol. If you want it to look like it's lit from an angle, you can set the startAnchor to a point off center:

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

If you don't want a border around your circles, set the linestyle color to clear and/or set the width to 0.0f (probably don't need to do both):

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

Set the size of your bubble:

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

and return your plot symbol:

return circlePlotSymbol;

That should do it. I don't have my code in front of me so I'm going from memory here (and please forgive any typos or bad syntax, as I don't have access to a compiler right now either), but hopefully this will be close enough to get you pointed in the right direction.



来源:https://stackoverflow.com/questions/21641601/ios-core-plot-scatter-plot-symbol-color-appearance

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