Sort Area Series by last value

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
TestAlways
Advanced
Posts: 228
Joined: Tue Aug 28, 2007 12:00 am
Location: Oregon, USA

Sort Area Series by last value

Post by TestAlways » Thu Mar 18, 2010 4:53 pm

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

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Sort Area Series by last value

Post by Yeray » Mon Mar 22, 2010 3:21 pm

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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply