From cf684284aa2b44e3cc3f65d09132e3aac4defd24 Mon Sep 17 00:00:00 2001 From: wp Date: Sat, 30 Jan 2021 22:56:26 +0000 Subject: [PATCH] TAChart: Extend listbox demo to show sorting and rearranging listbox series. git-svn-id: trunk@64449 - --- components/tachart/demo/listbox/Unit1.lfm | 62 +++++++++++++++-------- components/tachart/demo/listbox/Unit1.pas | 44 +++++----------- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/components/tachart/demo/listbox/Unit1.lfm b/components/tachart/demo/listbox/Unit1.lfm index 1429344ace..affacb0cae 100644 --- a/components/tachart/demo/listbox/Unit1.lfm +++ b/components/tachart/demo/listbox/Unit1.lfm @@ -1,16 +1,16 @@ object Form1: TForm1 Left = 265 - Height = 419 + Height = 412 Top = 182 Width = 892 Caption = 'TChartListbox demo' - ClientHeight = 419 + ClientHeight = 412 ClientWidth = 892 OnCreate = FormCreate LCLVersion = '2.1.0.0' object Chart: TChart Left = 292 - Height = 419 + Height = 412 Top = 0 Width = 457 AxisList = < @@ -53,6 +53,9 @@ object Form1: TForm1 BackColor = clWhite Foot.Brush.Color = clBtnFace Foot.Font.Color = clBlue + Legend.Alignment = laBottomCenter + Legend.ColumnCount = 4 + Legend.Visible = True Title.Brush.Color = clBtnFace Title.Font.Color = clBlue Title.Text.Strings = ( @@ -72,21 +75,25 @@ object Form1: TForm1 Title = 'exp(-x)' LinePen.Color = clGreen end + object GaussSeries: TLineSeries + Title = 'gaussian(x)' + LinePen.Color = clFuchsia + end end object ListboxPanel: TPanel Left = 754 - Height = 419 + Height = 412 Top = 0 Width = 138 Align = alRight BevelOuter = bvNone - ClientHeight = 419 + ClientHeight = 412 ClientWidth = 138 TabOrder = 1 object ChartListbox: TChartListbox AnchorSideBottom.Control = Panel2 Left = 6 - Height = 379 + Height = 372 Hint = 'Move up' Top = 6 Width = 126 @@ -104,7 +111,7 @@ object Form1: TForm1 object Panel2: TPanel Left = 0 Height = 22 - Top = 391 + Top = 384 Width = 138 Align = alBottom AutoSize = True @@ -158,7 +165,7 @@ object Form1: TForm1 end object Splitter: TSplitter Left = 749 - Height = 419 + Height = 412 Top = 0 Width = 5 Align = alRight @@ -166,14 +173,14 @@ object Form1: TForm1 end object Panel1: TPanel Left = 0 - Height = 419 + Height = 412 Top = 0 Width = 292 Align = alLeft AutoSize = True BevelInner = bvRaised BevelOuter = bvLowered - ClientHeight = 419 + ClientHeight = 412 ClientWidth = 292 TabOrder = 3 object BtnAddSeries: TButton @@ -217,7 +224,7 @@ object Form1: TForm1 AnchorSideBottom.Control = CbShowCheckboxes Left = 8 Height = 25 - Top = 269 + Top = 263 Width = 164 Anchors = [akLeft, akBottom] AutoSize = True @@ -245,11 +252,11 @@ object Form1: TForm1 AnchorSideBottom.Control = CbCheckStyle Left = 8 Height = 19 - Top = 310 + Top = 304 Width = 114 Anchors = [akLeft, akBottom] BorderSpacing.Left = 6 - BorderSpacing.Bottom = 12 + BorderSpacing.Bottom = 8 Caption = 'Show checkboxes' Checked = True OnChange = CbShowCheckboxesChange @@ -262,7 +269,7 @@ object Form1: TForm1 AnchorSideTop.Control = CbShowCheckboxes Left = 146 Height = 19 - Top = 310 + Top = 304 Width = 112 BorderSpacing.Left = 24 BorderSpacing.Right = 6 @@ -274,14 +281,14 @@ object Form1: TForm1 end object CbCheckStyle: TCheckBox AnchorSideLeft.Control = Panel1 - AnchorSideBottom.Control = CbKeepSeriesOut + AnchorSideBottom.Control = CbInverted Left = 8 Height = 19 - Top = 341 + Top = 331 Width = 91 Anchors = [akLeft, akBottom] BorderSpacing.Left = 6 - BorderSpacing.Bottom = 32 + BorderSpacing.Bottom = 8 Caption = 'Radiobuttons' OnChange = CbCheckStyleChange TabOrder = 6 @@ -294,7 +301,7 @@ object Form1: TForm1 AnchorSideRight.Side = asrBottom AnchorSideBottom.Control = BtnToggleChart Left = 8 - Height = 160 + Height = 154 Top = 103 Width = 276 Anchors = [akTop, akLeft, akRight, akBottom] @@ -324,7 +331,7 @@ object Form1: TForm1 AnchorSideTop.Side = asrCenter Left = 201 Height = 23 - Top = 339 + Top = 329 Width = 60 Alignment = taRightJustify BorderSpacing.Left = 4 @@ -340,7 +347,7 @@ object Form1: TForm1 AnchorSideTop.Side = asrCenter Left = 146 Height = 15 - Top = 343 + Top = 333 Width = 51 Caption = 'Columns:' ParentColor = False @@ -366,7 +373,7 @@ object Form1: TForm1 AnchorSideBottom.Side = asrBottom Left = 8 Height = 19 - Top = 392 + Top = 385 Width = 245 Anchors = [akLeft, akBottom] BorderSpacing.Left = 6 @@ -407,6 +414,19 @@ object Form1: TForm1 OnClick = BtnAddPointClick TabOrder = 11 end + object CbInverted: TCheckBox + AnchorSideLeft.Control = CbKeepSeriesOut + AnchorSideBottom.Control = CbKeepSeriesOut + Left = 8 + Height = 19 + Top = 358 + Width = 63 + Anchors = [akLeft, akBottom] + BorderSpacing.Bottom = 8 + Caption = 'Inverted' + OnChange = CbInvertedChange + TabOrder = 12 + end end object RandomChartSource: TRandomChartSource PointsNumber = 10 diff --git a/components/tachart/demo/listbox/Unit1.pas b/components/tachart/demo/listbox/Unit1.pas index 06c46706f2..4dbadf1a56 100644 --- a/components/tachart/demo/listbox/Unit1.pas +++ b/components/tachart/demo/listbox/Unit1.pas @@ -27,6 +27,8 @@ type CbShowSeriesIcon: TCheckBox; CbCheckStyle: TCheckBox; CbKeepSeriesOut: TCheckBox; + CbInverted: TCheckBox; + GaussSeries: TLineSeries; ExpSeries: TLineSeries; ChartListbox: TChartListbox; ColorDialog: TColorDialog; @@ -55,6 +57,7 @@ type procedure BtnToggleSINClick(Sender: TObject); procedure BtnAddPointClick(Sender: TObject); procedure BtnUpClick(Sender: TObject); + procedure CbInvertedChange(Sender: TObject); procedure CbShowCheckboxesChange(Sender: TObject); procedure CbShowSeriesIconChange(Sender: TObject); procedure CbCheckStyleChange(Sender: TObject); @@ -99,6 +102,7 @@ begin SinSeries.AddXY(x, sin(x)); CosSeries.AddXY(x, cos(x)); ExpSeries.AddXY(x, exp(-x)); + GaussSeries.AddXY(x, exp(-x*x)); end; end; @@ -158,61 +162,37 @@ end; procedure TForm1.BtnDownClick(Sender: TObject); var indx: Integer; - ser: TBasicChartSeries; begin indx := ChartListbox.ItemIndex; if (indx > -1) and (indx < ChartListbox.SeriesCount-1) then begin - ChartListbox.Chart := nil; - ser := ChartListbox.Series[indx]; - ser.Index := indx + 1; - ChartListbox.Chart := Chart; + ChartListbox.ExchangeSeries(indx, indx + 1); ChartListbox.ItemIndex := indx + 1; end; end; procedure TForm1.BtnSortClick(Sender: TObject); -var - List: TStringList; - i: Integer; - ser: TCustomChartSeries; begin - List := TStringList.Create; - try - for i:=0 to ChartListbox.SeriesCount-1 do - begin - ser := ChartListbox.Series[i]; - List.AddObject(ChartListbox.Series[i].Title, ser); - end; - List.Sort; - ChartListbox.Chart := nil; - for i := 0 to List.Count-1 do - begin - ser := TCustomChartSeries(List.Objects[i]); - ser.Index := i; - end; - ChartListbox.Chart := Chart; - finally - List.Free; - end; + ChartListbox.Sort; // Do use the descending parameter because sort order is already given by Legend.Inverted end; procedure TForm1.BtnUpClick(Sender: TObject); var indx: Integer; - ser: TBasicChartSeries; begin indx := ChartListbox.ItemIndex; if indx > 0 then begin - ChartListbox.Chart := nil; - ser := Chartlistbox.Series[indx]; - ser.Index := indx - 1; - ChartListbox.Chart := Chart; + ChartListbox.ExchangeSeries(indx, indx-1); ChartListbox.ItemIndex := indx - 1; end; end; +procedure TForm1.CbInvertedChange(Sender: TObject); +begin + Chart.Legend.Inverted := CbInverted.Checked; +end; + procedure TForm1.CbShowCheckboxesChange(Sender: TObject); begin with ChartListbox do