Hello Andreas,
Let me start for the end:
Andy wrote:Whats the formular TChart uses for this task?
Is it a simple linear interplolation of each R/G/B value or more complex?
The ColorRange is basically a linear interpolation. The MinValue is drawn in the EndColor, the MaxValue is drawn in the StartColor and the other values are drawn in a mixed color (IValueRangeInv is the inverse of the Values Range):
Code: Select all
if UseColorRange then
begin
if IValueRangeInv=0 then
result:=EndColor
else
begin
tmp:=AValue-MandatoryValueList.MinValue;
if tmp<0 then result:=EndColor
else
if AValue>MandatoryValueList.MaxValue then
result:=StartColor
else
begin
tmp:=tmp*IValueRangeInv;
result:=RangePercent(Min(1.0,tmp));
end;
end;
end
Andy wrote:How can I calculate gradient colors (maybe with midcolor)?
The following example seems to work fine for me here:
Code: Select all
uses TeeSurfa;
procedure TForm1.FormCreate(Sender: TObject);
var x, z, zmin, zmax: Integer;
begin
Chart1.View3D:=false;
Chart1.Legend.Visible:=false;
zmin:=-5;
zmax:=5;
with Chart1.AddSeries(TColorGridSeries) as TColorGridSeries do
begin
IrregularGrid:=true;
for x:=0 to 6-1 do
for z:=zmin to zmax-1 do
AddXYZ(x, z, z);
StartColor:=clRed;
EndColor:=clGreen;
end;
end;
However, if your zmin and zmax don't have the same absolute value, using ColorRange you won't have the 50% Green 50% Red at 0.
If this is the problem, a solution would be using two ColorGrid series, both using ColorRange. You could calculate the 50% Green 50% Red color (IZeroColor) and you could use one series to draw the positive values and the other for the negative:
Code: Select all
uses TeeSurfa;
procedure TForm1.FormCreate(Sender: TObject);
var x, z, xmin, xmax, zmin, zmax,
IStartColor, IEndColor, IZeroColor, IEndRed, IEndGreen, IEndBlue,
IRangeRed, IRangeGreen, IRangeBlue: Integer;
begin
Chart1.View3D:=false;
Chart1.Legend.Visible:=false;
xmin:=0;
xmax:=10;
zmin:=-5;
zmax:=10;
IStartColor:=clRed;
IEndColor :=clGreen;
IEndRed :=GetRValue(IEndColor);
IEndGreen :=GetGValue(IEndColor);
IEndBlue :=GetBValue(IEndColor);
IRangeRed :=Integer(GetRValue(IStartColor))-IEndRed;
IRangeGreen:=Integer(GetGValue(IStartColor))-IEndGreen;
IRangeBlue :=Integer(GetBValue(IStartColor))-IEndBlue;
IZeroColor :=RGB(IEndRed +Round(0.5*IRangeRed),
IEndGreen+Round(0.5*IRangeGreen),
IEndBlue +Round(0.5*IRangeBlue));
with Chart1.AddSeries(TColorGridSeries) as TColorGridSeries do
begin
IrregularGrid:=true;
Pen.Visible:=false;
for x:=xmin to xmax-1 do
for z:=zmin to 0 do
AddXYZ(x, z, z);
StartColor:=IZeroColor;
EndColor:=IEndColor;
end;
with Chart1.AddSeries(TColorGridSeries) as TColorGridSeries do
begin
IrregularGrid:=true;
Pen.Visible:=false;
for x:=xmin to xmax-1 do
for z:=0 to zmax-1 do
AddXYZ(x, z, z);
StartColor:=IStartColor;
EndColor:=IZeroColor;
end;
end;