Search code examples
ioscore-plotalphascatter-plot

Coreplot - change alpha of gradient


I am trying to change alpha of the gradients I am using below my scatter plot:

//add gradient to line
CPTColor *underLineGradientStartColor       = [CPTColor colorWithComponentRed:CPTFloat(0.4) green:CPTFloat(0.2) blue:CPTFloat(0.9) alpha:CPTFloat(0.6)];
CPTColor *underLineGradientEndColor         = [CPTColor colorWithComponentRed:CPTFloat(0.4) green:CPTFloat(0.2) blue:CPTFloat(0.9) alpha:CPTFloat(1.0)];
CPTGradient *underLineGradient = [CPTGradient gradientWithBeginningColor:underLineGradientStartColor endingColor:underLineGradientEndColor];
underLineGradient.angle = -90.0;
CPTFill *underLineGradientFill = [CPTFill fillWithGradient:underLineGradient];
dataSourceLinePlot.areaFill      = underLineGradientFill;

To set alpha I would like to perform the opposite operation ->get gradient->get start/end colours and change alpha of them. CPTFill, unfortunately, doesn't have any properties that would be useful. How to change the alpha?


Solution

  • CPTFill is a class cluster that encapsulates three types of fills: colors, images, and gradients. It doesn't expose the contents of the fill.

    You don't say how you obtain the gradient you want to change. You'll need to create a new fill to change the fill on the graph. Keep track of the old value somewhere else if needed to determine the new colors for the gradient.