Bueno, no sé si es demasiado bonito, pero supongo que podría hacer dos trazados separados con el mismo dataSource, digamos positivePlot y negativePlot.
CPScatterPlot *positivePlot = [[[CPScatterPlot alloc] init] autorelease];
positivePlot.identifier = @"PositivePlot";
positivePlot.dataSource = self;
[graph addPlot:positivePlot];
CPScatterPlot *negativevePlot = [[[CPScatterPlot alloc] init] autorelease];
negativevePlot.identifier = @"NegativePlot";
negativePlot.dataSource = self;
[graph addPlot:negativePlot];
Ahora, si configura su plotSpaces adecuadamente, puede separar los valores positivos y negativos y configurar cada parcela adecuada, incluyendo el área de gradiente:
CPXYPlotSpace *positivePlotSpace = [graph newPlotSpace];
positivePlotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0)
length:CPDecimalFromFloat(100)];
positivePlotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0)
length:CPDecimalFromFloat(100)];
CPXYPlotSpace *negativevePlotSpace = [graph newPlotSpace];
negativePlotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-100)
length:CPDecimalFromFloat(100)];
negativePlotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0)
length:CPDecimalFromFloat(100)];
// Plots configuration
//POSITIVE VALUES
positivePlot.plotSpace = positivePlotSpace;
// Green for positive
CPColor *areaColor = [CPColor colorWithComponentRed:0.0
green:1.0
blue:0.0
alpha:1.0];
CPGradient *areaGradient = [CPGradient gradientWithBeginningColor:areaColor
endingColor:[CPColor clearColor]];
areaGradient.angle = -90.0f;
CPFill *areaGradientFill = [CPFill fillWithGradient:areaGradient];
positivePlot.areaFill = areaGradientFill;
//NEGATIVE VALUES
negativePlot.plotSpace = negativePlotSpace;
// Red for negative
areaColor = [CPColor colorWithComponentRed:1.0
green:0.0
blue:0.0
alpha:1.0];
areaGradient = [CPGradient gradientWithBeginningColor:areaColor
endingColor:[CPColor clearColor]];
areaGradient.angle = -90.0f;
areaGradientFill = [CPFill fillWithGradient:areaGradient];
negativePlot.areaFill = areaGradientFill;
NOTA: Esta es la parte superior de mi cabeza, ya que no tengo documentos de Core-Plot aquí, o una configuración que funcione para probar esto, por lo que la sintaxis o algo podría estar apagado, pero creo que el concepto general debería funcionar.
Saludos
Es probable que necesita para normalizar sus valores. Por lo que puedo ver, CPGradient solo acepta 'CGFloat 0 - 1'. Entonces, si sus valores van desde -1024 hasta +1024, deberá agregar un desplazamiento y dividir por el rango total. Eso te dará un número del 0-1. No puedo responder con certeza, b/c. Nunca he trabajado con CorePlot. –
@Stephen Furlani: gracias por la entrada. No tengo claro lo que has dicho. ¿Puede explicarlo en detalle? –
Ya sabe, ya sea de antemano, o mirando su conjunto de datos, que todos los valores 'n' son tales que' j ≤ n ≤ k'. Entonces, puede obtener el valor de gradiente como '(n - j)/(k - j)', que estará en el rango '[0-1]'. Esto interpola linealmente entre 'j' y' k'. – tJener