mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-26 23:23:48 +02:00
TAChart: Extend listbox demo to show sorting and rearranging listbox series.
git-svn-id: trunk@64449 -
This commit is contained in:
parent
705298159f
commit
cf684284aa
@ -1,16 +1,16 @@
|
|||||||
object Form1: TForm1
|
object Form1: TForm1
|
||||||
Left = 265
|
Left = 265
|
||||||
Height = 419
|
Height = 412
|
||||||
Top = 182
|
Top = 182
|
||||||
Width = 892
|
Width = 892
|
||||||
Caption = 'TChartListbox demo'
|
Caption = 'TChartListbox demo'
|
||||||
ClientHeight = 419
|
ClientHeight = 412
|
||||||
ClientWidth = 892
|
ClientWidth = 892
|
||||||
OnCreate = FormCreate
|
OnCreate = FormCreate
|
||||||
LCLVersion = '2.1.0.0'
|
LCLVersion = '2.1.0.0'
|
||||||
object Chart: TChart
|
object Chart: TChart
|
||||||
Left = 292
|
Left = 292
|
||||||
Height = 419
|
Height = 412
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 457
|
Width = 457
|
||||||
AxisList = <
|
AxisList = <
|
||||||
@ -53,6 +53,9 @@ object Form1: TForm1
|
|||||||
BackColor = clWhite
|
BackColor = clWhite
|
||||||
Foot.Brush.Color = clBtnFace
|
Foot.Brush.Color = clBtnFace
|
||||||
Foot.Font.Color = clBlue
|
Foot.Font.Color = clBlue
|
||||||
|
Legend.Alignment = laBottomCenter
|
||||||
|
Legend.ColumnCount = 4
|
||||||
|
Legend.Visible = True
|
||||||
Title.Brush.Color = clBtnFace
|
Title.Brush.Color = clBtnFace
|
||||||
Title.Font.Color = clBlue
|
Title.Font.Color = clBlue
|
||||||
Title.Text.Strings = (
|
Title.Text.Strings = (
|
||||||
@ -72,21 +75,25 @@ object Form1: TForm1
|
|||||||
Title = 'exp(-x)'
|
Title = 'exp(-x)'
|
||||||
LinePen.Color = clGreen
|
LinePen.Color = clGreen
|
||||||
end
|
end
|
||||||
|
object GaussSeries: TLineSeries
|
||||||
|
Title = 'gaussian(x)'
|
||||||
|
LinePen.Color = clFuchsia
|
||||||
|
end
|
||||||
end
|
end
|
||||||
object ListboxPanel: TPanel
|
object ListboxPanel: TPanel
|
||||||
Left = 754
|
Left = 754
|
||||||
Height = 419
|
Height = 412
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 138
|
Width = 138
|
||||||
Align = alRight
|
Align = alRight
|
||||||
BevelOuter = bvNone
|
BevelOuter = bvNone
|
||||||
ClientHeight = 419
|
ClientHeight = 412
|
||||||
ClientWidth = 138
|
ClientWidth = 138
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
object ChartListbox: TChartListbox
|
object ChartListbox: TChartListbox
|
||||||
AnchorSideBottom.Control = Panel2
|
AnchorSideBottom.Control = Panel2
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 379
|
Height = 372
|
||||||
Hint = 'Move up'
|
Hint = 'Move up'
|
||||||
Top = 6
|
Top = 6
|
||||||
Width = 126
|
Width = 126
|
||||||
@ -104,7 +111,7 @@ object Form1: TForm1
|
|||||||
object Panel2: TPanel
|
object Panel2: TPanel
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 22
|
Height = 22
|
||||||
Top = 391
|
Top = 384
|
||||||
Width = 138
|
Width = 138
|
||||||
Align = alBottom
|
Align = alBottom
|
||||||
AutoSize = True
|
AutoSize = True
|
||||||
@ -158,7 +165,7 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
object Splitter: TSplitter
|
object Splitter: TSplitter
|
||||||
Left = 749
|
Left = 749
|
||||||
Height = 419
|
Height = 412
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 5
|
Width = 5
|
||||||
Align = alRight
|
Align = alRight
|
||||||
@ -166,14 +173,14 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
object Panel1: TPanel
|
object Panel1: TPanel
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 419
|
Height = 412
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 292
|
Width = 292
|
||||||
Align = alLeft
|
Align = alLeft
|
||||||
AutoSize = True
|
AutoSize = True
|
||||||
BevelInner = bvRaised
|
BevelInner = bvRaised
|
||||||
BevelOuter = bvLowered
|
BevelOuter = bvLowered
|
||||||
ClientHeight = 419
|
ClientHeight = 412
|
||||||
ClientWidth = 292
|
ClientWidth = 292
|
||||||
TabOrder = 3
|
TabOrder = 3
|
||||||
object BtnAddSeries: TButton
|
object BtnAddSeries: TButton
|
||||||
@ -217,7 +224,7 @@ object Form1: TForm1
|
|||||||
AnchorSideBottom.Control = CbShowCheckboxes
|
AnchorSideBottom.Control = CbShowCheckboxes
|
||||||
Left = 8
|
Left = 8
|
||||||
Height = 25
|
Height = 25
|
||||||
Top = 269
|
Top = 263
|
||||||
Width = 164
|
Width = 164
|
||||||
Anchors = [akLeft, akBottom]
|
Anchors = [akLeft, akBottom]
|
||||||
AutoSize = True
|
AutoSize = True
|
||||||
@ -245,11 +252,11 @@ object Form1: TForm1
|
|||||||
AnchorSideBottom.Control = CbCheckStyle
|
AnchorSideBottom.Control = CbCheckStyle
|
||||||
Left = 8
|
Left = 8
|
||||||
Height = 19
|
Height = 19
|
||||||
Top = 310
|
Top = 304
|
||||||
Width = 114
|
Width = 114
|
||||||
Anchors = [akLeft, akBottom]
|
Anchors = [akLeft, akBottom]
|
||||||
BorderSpacing.Left = 6
|
BorderSpacing.Left = 6
|
||||||
BorderSpacing.Bottom = 12
|
BorderSpacing.Bottom = 8
|
||||||
Caption = 'Show checkboxes'
|
Caption = 'Show checkboxes'
|
||||||
Checked = True
|
Checked = True
|
||||||
OnChange = CbShowCheckboxesChange
|
OnChange = CbShowCheckboxesChange
|
||||||
@ -262,7 +269,7 @@ object Form1: TForm1
|
|||||||
AnchorSideTop.Control = CbShowCheckboxes
|
AnchorSideTop.Control = CbShowCheckboxes
|
||||||
Left = 146
|
Left = 146
|
||||||
Height = 19
|
Height = 19
|
||||||
Top = 310
|
Top = 304
|
||||||
Width = 112
|
Width = 112
|
||||||
BorderSpacing.Left = 24
|
BorderSpacing.Left = 24
|
||||||
BorderSpacing.Right = 6
|
BorderSpacing.Right = 6
|
||||||
@ -274,14 +281,14 @@ object Form1: TForm1
|
|||||||
end
|
end
|
||||||
object CbCheckStyle: TCheckBox
|
object CbCheckStyle: TCheckBox
|
||||||
AnchorSideLeft.Control = Panel1
|
AnchorSideLeft.Control = Panel1
|
||||||
AnchorSideBottom.Control = CbKeepSeriesOut
|
AnchorSideBottom.Control = CbInverted
|
||||||
Left = 8
|
Left = 8
|
||||||
Height = 19
|
Height = 19
|
||||||
Top = 341
|
Top = 331
|
||||||
Width = 91
|
Width = 91
|
||||||
Anchors = [akLeft, akBottom]
|
Anchors = [akLeft, akBottom]
|
||||||
BorderSpacing.Left = 6
|
BorderSpacing.Left = 6
|
||||||
BorderSpacing.Bottom = 32
|
BorderSpacing.Bottom = 8
|
||||||
Caption = 'Radiobuttons'
|
Caption = 'Radiobuttons'
|
||||||
OnChange = CbCheckStyleChange
|
OnChange = CbCheckStyleChange
|
||||||
TabOrder = 6
|
TabOrder = 6
|
||||||
@ -294,7 +301,7 @@ object Form1: TForm1
|
|||||||
AnchorSideRight.Side = asrBottom
|
AnchorSideRight.Side = asrBottom
|
||||||
AnchorSideBottom.Control = BtnToggleChart
|
AnchorSideBottom.Control = BtnToggleChart
|
||||||
Left = 8
|
Left = 8
|
||||||
Height = 160
|
Height = 154
|
||||||
Top = 103
|
Top = 103
|
||||||
Width = 276
|
Width = 276
|
||||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||||
@ -324,7 +331,7 @@ object Form1: TForm1
|
|||||||
AnchorSideTop.Side = asrCenter
|
AnchorSideTop.Side = asrCenter
|
||||||
Left = 201
|
Left = 201
|
||||||
Height = 23
|
Height = 23
|
||||||
Top = 339
|
Top = 329
|
||||||
Width = 60
|
Width = 60
|
||||||
Alignment = taRightJustify
|
Alignment = taRightJustify
|
||||||
BorderSpacing.Left = 4
|
BorderSpacing.Left = 4
|
||||||
@ -340,7 +347,7 @@ object Form1: TForm1
|
|||||||
AnchorSideTop.Side = asrCenter
|
AnchorSideTop.Side = asrCenter
|
||||||
Left = 146
|
Left = 146
|
||||||
Height = 15
|
Height = 15
|
||||||
Top = 343
|
Top = 333
|
||||||
Width = 51
|
Width = 51
|
||||||
Caption = 'Columns:'
|
Caption = 'Columns:'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
@ -366,7 +373,7 @@ object Form1: TForm1
|
|||||||
AnchorSideBottom.Side = asrBottom
|
AnchorSideBottom.Side = asrBottom
|
||||||
Left = 8
|
Left = 8
|
||||||
Height = 19
|
Height = 19
|
||||||
Top = 392
|
Top = 385
|
||||||
Width = 245
|
Width = 245
|
||||||
Anchors = [akLeft, akBottom]
|
Anchors = [akLeft, akBottom]
|
||||||
BorderSpacing.Left = 6
|
BorderSpacing.Left = 6
|
||||||
@ -407,6 +414,19 @@ object Form1: TForm1
|
|||||||
OnClick = BtnAddPointClick
|
OnClick = BtnAddPointClick
|
||||||
TabOrder = 11
|
TabOrder = 11
|
||||||
end
|
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
|
end
|
||||||
object RandomChartSource: TRandomChartSource
|
object RandomChartSource: TRandomChartSource
|
||||||
PointsNumber = 10
|
PointsNumber = 10
|
||||||
|
@ -27,6 +27,8 @@ type
|
|||||||
CbShowSeriesIcon: TCheckBox;
|
CbShowSeriesIcon: TCheckBox;
|
||||||
CbCheckStyle: TCheckBox;
|
CbCheckStyle: TCheckBox;
|
||||||
CbKeepSeriesOut: TCheckBox;
|
CbKeepSeriesOut: TCheckBox;
|
||||||
|
CbInverted: TCheckBox;
|
||||||
|
GaussSeries: TLineSeries;
|
||||||
ExpSeries: TLineSeries;
|
ExpSeries: TLineSeries;
|
||||||
ChartListbox: TChartListbox;
|
ChartListbox: TChartListbox;
|
||||||
ColorDialog: TColorDialog;
|
ColorDialog: TColorDialog;
|
||||||
@ -55,6 +57,7 @@ type
|
|||||||
procedure BtnToggleSINClick(Sender: TObject);
|
procedure BtnToggleSINClick(Sender: TObject);
|
||||||
procedure BtnAddPointClick(Sender: TObject);
|
procedure BtnAddPointClick(Sender: TObject);
|
||||||
procedure BtnUpClick(Sender: TObject);
|
procedure BtnUpClick(Sender: TObject);
|
||||||
|
procedure CbInvertedChange(Sender: TObject);
|
||||||
procedure CbShowCheckboxesChange(Sender: TObject);
|
procedure CbShowCheckboxesChange(Sender: TObject);
|
||||||
procedure CbShowSeriesIconChange(Sender: TObject);
|
procedure CbShowSeriesIconChange(Sender: TObject);
|
||||||
procedure CbCheckStyleChange(Sender: TObject);
|
procedure CbCheckStyleChange(Sender: TObject);
|
||||||
@ -99,6 +102,7 @@ begin
|
|||||||
SinSeries.AddXY(x, sin(x));
|
SinSeries.AddXY(x, sin(x));
|
||||||
CosSeries.AddXY(x, cos(x));
|
CosSeries.AddXY(x, cos(x));
|
||||||
ExpSeries.AddXY(x, exp(-x));
|
ExpSeries.AddXY(x, exp(-x));
|
||||||
|
GaussSeries.AddXY(x, exp(-x*x));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -158,61 +162,37 @@ end;
|
|||||||
procedure TForm1.BtnDownClick(Sender: TObject);
|
procedure TForm1.BtnDownClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
indx: Integer;
|
indx: Integer;
|
||||||
ser: TBasicChartSeries;
|
|
||||||
begin
|
begin
|
||||||
indx := ChartListbox.ItemIndex;
|
indx := ChartListbox.ItemIndex;
|
||||||
if (indx > -1) and (indx < ChartListbox.SeriesCount-1) then
|
if (indx > -1) and (indx < ChartListbox.SeriesCount-1) then
|
||||||
begin
|
begin
|
||||||
ChartListbox.Chart := nil;
|
ChartListbox.ExchangeSeries(indx, indx + 1);
|
||||||
ser := ChartListbox.Series[indx];
|
|
||||||
ser.Index := indx + 1;
|
|
||||||
ChartListbox.Chart := Chart;
|
|
||||||
ChartListbox.ItemIndex := indx + 1;
|
ChartListbox.ItemIndex := indx + 1;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.BtnSortClick(Sender: TObject);
|
procedure TForm1.BtnSortClick(Sender: TObject);
|
||||||
var
|
|
||||||
List: TStringList;
|
|
||||||
i: Integer;
|
|
||||||
ser: TCustomChartSeries;
|
|
||||||
begin
|
begin
|
||||||
List := TStringList.Create;
|
ChartListbox.Sort; // Do use the descending parameter because sort order is already given by Legend.Inverted
|
||||||
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;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.BtnUpClick(Sender: TObject);
|
procedure TForm1.BtnUpClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
indx: Integer;
|
indx: Integer;
|
||||||
ser: TBasicChartSeries;
|
|
||||||
begin
|
begin
|
||||||
indx := ChartListbox.ItemIndex;
|
indx := ChartListbox.ItemIndex;
|
||||||
if indx > 0 then
|
if indx > 0 then
|
||||||
begin
|
begin
|
||||||
ChartListbox.Chart := nil;
|
ChartListbox.ExchangeSeries(indx, indx-1);
|
||||||
ser := Chartlistbox.Series[indx];
|
|
||||||
ser.Index := indx - 1;
|
|
||||||
ChartListbox.Chart := Chart;
|
|
||||||
ChartListbox.ItemIndex := indx - 1;
|
ChartListbox.ItemIndex := indx - 1;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.CbInvertedChange(Sender: TObject);
|
||||||
|
begin
|
||||||
|
Chart.Legend.Inverted := CbInverted.Checked;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TForm1.CbShowCheckboxesChange(Sender: TObject);
|
procedure TForm1.CbShowCheckboxesChange(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
with ChartListbox do
|
with ChartListbox do
|
||||||
|
Loading…
Reference in New Issue
Block a user