Page 1 of 1
Sort Area Series by last value
Posted: Thu Mar 18, 2010 4:53 pm
by 10546565
I have a chart that has a number of area series. I would like to z-order the series with the one in the back with the highest last-value of the series, and the one in the front lowest last value of the series.
How can I do that?
Thanks
Ed Dressel
Re: Sort Area Series by last value
Posted: Mon Mar 22, 2010 3:21 pm
by yeray
Hi Ed,
Is the following what you are trying to do?
Code: Select all
uses series;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
for i:=0 to 3 do with Chart1.AddSeries(TAreaSeries.Create(self)) do FillSampleValues();
end;
procedure TForm1.Button1Click(Sender: TObject);
var i, n: Integer;
swapped: Boolean;
begin
n:=Chart1.SeriesCount;
swapped:=true;
while swapped do
begin
swapped:=false;
for i:=0 to n-2 do
begin
if Chart1[i].YValue[Chart1[i].Count-1] < Chart1[i+1].YValue[Chart1[i+1].Count-1] then
begin
Chart1.ExchangeSeries(i, i+1);
swapped:=true;
end;
end;
n:=n-1;
end;
end;