Hi Bruce,
I've looked and can't find a corresponding list to set the color - maybe the best way is to set the color as the chart is drawn?
Not exactly, you need to do this:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
Var X,Y,O : Array of Double; // TChartValues
C : Array of TColor;
t : Integer;
Num : Integer;
begin
{ 100 points }
Num:= 100;
{ allocate our custom arrays }
SetLength(X,Num);
SetLength(Y,Num);
SetLength(O,Num);
SetLength(C,Num);
{ fill data in our custom arrays }
X[0]:=0;
Y[0]:=Random(10000);
O[0]:=Random(1000);
C[0]:=RGB(Random(255),Random(255),Random(255));
for t:=1 to Num-1 do
begin
X[t]:=t;
Y[t]:=Y[t-1]+Random(101)-50;
O[t]:=Y[t-1]+Random(1000)-500;
C[t]:=RGB(Random(255),Random(255),Random(255));
end;
with Series1.XValues do
begin
Value:=TChartValues(x);
Count:=length(x);
Modified:=True;
end;
with Series1.YValues do
begin
Value:=TChartValues(y);
Count:=length(y);
Modified:=True;
end;
with Series1.OffsetValues do
begin
Value:=TChartValues(O);
Count:=length(O);
Modified:=True;
end;
for t:=0 to Series1.Count-1 do
Series1.ValueColor[t]:=C[t];
Series1.Repaint;
end;
Do you have any suggestion - I want to color bars with a min value above zero red and ones with a min value below zero blue...
Ok, in that case it could be:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
Var X,Y,O : Array of Double; // TChartValues
t : Integer;
Num : Integer;
tmp : Double;
begin
{ 100 points }
Num:= 100;
{ allocate our custom arrays }
SetLength(X,Num);
SetLength(Y,Num);
SetLength(O,Num);
{ fill data in our custom arrays }
X[0]:=0;
Y[0]:=Random(10000);
O[0]:=Random(1000);
for t:=1 to Num-1 do
begin
X[t]:=t;
Y[t]:=Y[t-1]+Random(101)-50;
O[t]:=Y[t-1]+Random(1000)-500;
end;
with Series1.XValues do
begin
Value:=TChartValues(x);
Count:=length(x);
Modified:=True;
end;
with Series1.YValues do
begin
Value:=TChartValues(y);
Count:=length(y);
Modified:=True;
end;
with Series1.OffsetValues do
begin
Value:=TChartValues(O);
Count:=length(O);
Modified:=True;
end;
for t:=0 to Series1.Count-1 do
begin
tmp:=Y[t]+O[t];
if tmp > 0 then
Series1.ValueColor[t]:=clRed
else
Series1.ValueColor[t]:=clBlue;
end;
Series1.Repaint;
end;