diff --git a/components/tachart/demo/chartsource/chartsourcedemo.lpi b/components/tachart/demo/chartsource/chartsourcedemo.lpi index 373c57be88..7dc3898419 100644 --- a/components/tachart/demo/chartsource/chartsourcedemo.lpi +++ b/components/tachart/demo/chartsource/chartsourcedemo.lpi @@ -1,15 +1,15 @@ - + + - @@ -21,11 +21,14 @@ + + + - + diff --git a/components/tachart/demo/chartsource/main.lfm b/components/tachart/demo/chartsource/main.lfm index ce5a09e91f..af04734986 100644 --- a/components/tachart/demo/chartsource/main.lfm +++ b/components/tachart/demo/chartsource/main.lfm @@ -8,33 +8,24 @@ object Form1: TForm1 ClientWidth = 637 OnCreate = FormCreate LCLVersion = '2.1.0.0' - object Splitter1: TSplitter - Left = 632 - Height = 438 - Top = 0 - Width = 5 - Align = alRight - Beveled = True - ResizeAnchor = akRight - end object PageControl1: TPageControl Left = 0 Height = 438 Top = 0 - Width = 632 + Width = 637 ActivePage = tsBasic Align = alClient TabIndex = 0 - TabOrder = 1 + TabOrder = 0 object tsBasic: TTabSheet Caption = 'Basic' ClientHeight = 410 - ClientWidth = 624 + ClientWidth = 629 object Memo1: TMemo Left = 0 Height = 34 Top = 0 - Width = 624 + Width = 629 Align = alTop Lines.Strings = ( 'Modify sources at design-time.' @@ -68,6 +59,7 @@ object Form1: TForm1 'TAChart' ) Align = alClient + Color = clWindow object Chart2LineSeries1: TLineSeries LinePen.Color = clRed Pointer.Brush.Color = clRed @@ -82,7 +74,7 @@ object Form1: TForm1 end end object Chart1: TChart - Left = 333 + Left = 338 Height = 376 Top = 34 Width = 291 @@ -107,6 +99,7 @@ object Form1: TForm1 'TAChart' ) Align = alRight + Color = clWindow object Chart1BarSeries1: TBarSeries BarBrush.Color = clRed Source = RandomChartSource1 @@ -120,16 +113,24 @@ object Form1: TForm1 Source = ListChartSource1 end end + object Splitter1: TSplitter + Left = 333 + Height = 376 + Top = 34 + Width = 5 + Align = alRight + ResizeAnchor = akRight + end end object tsStatistics: TTabSheet Caption = 'Statistics' ClientHeight = 410 - ClientWidth = 624 + ClientWidth = 629 object chCalc: TChart Left = 0 Height = 369 Top = 0 - Width = 624 + Width = 629 AxisList = < item Marks.LabelBrush.Style = bsClear @@ -156,6 +157,7 @@ object Form1: TForm1 'TAChart' ) Align = alClient + Color = clWindow object chCalcLineSeries1: TLineSeries Title = 'Data' LineType = ltNone @@ -181,11 +183,11 @@ object Form1: TForm1 Left = 0 Height = 41 Top = 369 - Width = 624 + Width = 629 Align = alBottom AutoSize = True ClientHeight = 41 - ClientWidth = 624 + ClientWidth = 629 TabOrder = 1 object cbCumulative: TCheckBox AnchorSideLeft.Control = Panel2 @@ -231,12 +233,12 @@ object Form1: TForm1 object tsDerivative: TTabSheet Caption = 'Derivative' ClientHeight = 410 - ClientWidth = 624 + ClientWidth = 629 object chDerivative: TChart Left = 0 Height = 317 Top = 0 - Width = 624 + Width = 629 AxisList = < item Grid.Color = clSilver @@ -268,6 +270,7 @@ object Form1: TForm1 'TAChart' ) Align = alClient + Color = clWindow DoubleBuffered = True object chDerivativeLineOrig: TLineSeries Title = 'y' @@ -280,12 +283,14 @@ object Form1: TForm1 end end object rgDataShape: TRadioGroup - Left = 0 + Left = 6 Height = 54 Top = 317 - Width = 624 + Width = 617 Align = alBottom AutoFill = True + BorderSpacing.Left = 6 + BorderSpacing.Right = 6 Caption = 'Functions' ChildSizing.LeftRightSpacing = 6 ChildSizing.TopBottomSpacing = 6 @@ -296,7 +301,7 @@ object Form1: TForm1 ChildSizing.Layout = cclLeftToRightThenTopToBottom ChildSizing.ControlsPerLine = 7 ClientHeight = 34 - ClientWidth = 620 + ClientWidth = 613 Columns = 7 ItemIndex = 0 Items.Strings = ( @@ -316,12 +321,12 @@ object Form1: TForm1 Left = 0 Height = 39 Top = 371 - Width = 624 + Width = 629 Align = alBottom AutoSize = True BevelOuter = bvNone ClientHeight = 39 - ClientWidth = 624 + ClientWidth = 629 TabOrder = 2 object lblAccumulationRange: TLabel AnchorSideLeft.Control = Panel1 @@ -389,6 +394,97 @@ object Form1: TForm1 end end end + object tsSorted: TTabSheet + Caption = 'Sorted' + ClientHeight = 410 + ClientWidth = 629 + object btnSort: TButton + AnchorSideLeft.Control = tsSorted + AnchorSideTop.Control = tsSorted + Left = 8 + Height = 25 + Top = 8 + Width = 230 + AutoSize = True + BorderSpacing.Left = 8 + BorderSpacing.Top = 8 + Caption = 'Sort/unsort data by number of visitors!' + OnClick = btnSortClick + TabOrder = 0 + end + object BubbleChart: TChart + AnchorSideLeft.Control = tsSorted + AnchorSideTop.Control = btnSort + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = tsSorted + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = tsSorted + AnchorSideBottom.Side = asrBottom + Left = 8 + Height = 361 + Top = 41 + Width = 613 + AxisList = < + item + Visible = False + Marks.LabelBrush.Style = bsClear + Minors = <> + Title.LabelFont.Orientation = 900 + Title.LabelBrush.Style = bsClear + end + item + Alignment = calBottom + Marks.Format = '%4:.9g' + Marks.LabelBrush.Style = bsClear + Marks.Source = SortedChartSource + Marks.Style = smsXValue + Minors = <> + Title.LabelBrush.Style = bsClear + end> + Foot.Brush.Color = clBtnFace + Foot.Font.Color = clBlue + Margins.Left = 20 + Margins.Right = 40 + Title.Brush.Color = clBtnFace + Title.Brush.Style = bsClear + Title.Font.Color = clBlue + Title.Text.Strings = ( + 'Locations of World Exposition X, and numbers of visitors (given by bubble size)' + ) + Title.Visible = True + OnAfterPaint = BubbleChartAfterPaint + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Around = 8 + Color = clWindow + object BubbleSeries: TBubbleSeries + AxisIndexX = 1 + AxisIndexY = 0 + BubbleRadiusUnits = bruY + MarkPositions = lmpPositive + Marks.Attachment = maCenter + Marks.Distance = 0 + Marks.LabelFont.Orientation = 900 + Marks.Format = '%2:s' + Marks.LabelBrush.Color = clWhite + Marks.Style = smsLabel + OverrideColor = [bocBrush] + Source = SortedChartSource + end + end + object lblSortInfo: TLabel + AnchorSideLeft.Control = btnSort + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = btnSort + AnchorSideTop.Side = asrCenter + Left = 246 + Height = 15 + Top = 13 + Width = 55 + BorderSpacing.Left = 8 + Caption = 'lblSortInfo' + ParentColor = False + end + end end object RandomChartSource1: TRandomChartSource PointsNumber = 8 @@ -397,8 +493,8 @@ object Form1: TForm1 XMin = -5 YMax = 10 YMin = 0 - left = 240 - top = 204 + left = 88 + top = 112 end object ListChartSource1: TListChartSource DataPoints.Strings = ( @@ -408,22 +504,22 @@ object Form1: TForm1 '0|1|?|' '3|2|?|' ) - left = 240 - top = 260 + left = 88 + top = 168 end object ccsSum: TCalculatedChartSource AccumulationMethod = camSum AccumulationRange = 0 Origin = RandomChartSource2 - left = 504 - top = 112 + left = 240 + top = 168 end object ccsAvg: TCalculatedChartSource AccumulationMethod = camAverage AccumulationRange = 5 Origin = RandomChartSource2 - left = 504 - top = 168 + left = 240 + top = 224 end object RandomChartSource2: TRandomChartSource PointsNumber = 25 @@ -432,17 +528,31 @@ object Form1: TForm1 XMin = -10 YMax = 8 YMin = 1 - left = 504 - top = 268 + left = 240 + top = 112 end object lcsDerivative: TListChartSource - left = 156 - top = 84 + left = 376 + top = 112 end object ccsDerivative: TCalculatedChartSource AccumulationMethod = camDerivative Origin = lcsDerivative - left = 156 - top = 140 + left = 376 + top = 168 + end + object UserDefinedChartSource: TUserDefinedChartSource + OnGetChartDataItem = UserDefinedChartSourceGetChartDataItem + YCount = 2 + left = 528 + top = 112 + end + object SortedChartSource: TSortedChartSource + Origin = UserDefinedChartSource + SortBy = sbY + SortDir = sdDescending + SortIndex = 1 + left = 528 + top = 168 end end diff --git a/components/tachart/demo/chartsource/main.pas b/components/tachart/demo/chartsource/main.pas index de312b6335..fa38622b82 100644 --- a/components/tachart/demo/chartsource/main.pas +++ b/components/tachart/demo/chartsource/main.pas @@ -5,14 +5,22 @@ unit Main; interface uses - ComCtrls, ExtCtrls, Spin, StdCtrls, Forms, TAGraph, TASeries, TASources, - Classes; + Classes, StdCtrls, ComCtrls, ExtCtrls, Spin, Forms, + TAGraph, TASeries, TACustomSource, TASources, TAMultiSeries, TAChartUtils; type + TDataForSorting = record + Year: Integer; + CityName: String; + Visitors: Integer; + Color: TChartColor; + end; { TForm1 } TForm1 = class(TForm) + btnSort: TButton; + BubbleSeries: TBubbleSeries; cbAccDirDerivative: TComboBox; ccsDerivative: TCalculatedChartSource; cbCumulative: TCheckBox; @@ -21,6 +29,7 @@ type Chart1: TChart; Chart1BarSeries1: TBarSeries; Chart1LineSeries1: TLineSeries; + BubbleChart: TChart; chDerivativeLineOrig: TLineSeries; chDerivativeLineDeriv: TLineSeries; Chart1LineSeries4: TLineSeries; @@ -35,6 +44,7 @@ type chCalcLineSeriesSum: TLineSeries; cbAccDirStatistics: TComboBox; cbSmooth: TCheckBox; + lblSortInfo: TLabel; seAccumulationRange: TSpinEdit; lblAccumulationRange: TLabel; ListChartSource1: TListChartSource; @@ -46,18 +56,29 @@ type rgDataShape: TRadioGroup; RandomChartSource1: TRandomChartSource; RandomChartSource2: TRandomChartSource; + SortedChartSource: TSortedChartSource; Splitter1: TSplitter; + tsSorted: TTabSheet; tsDerivative: TTabSheet; tsStatistics: TTabSheet; tsBasic: TTabSheet; + UserDefinedChartSource: TUserDefinedChartSource; + procedure btnSortClick(Sender: TObject); + procedure BubbleChartAfterPaint(ASender: TChart); procedure cbAccDirDerivativeChange(Sender: TObject); procedure cbAccDirStatisticsChange(Sender: TObject); procedure cbCumulativeChange(Sender: TObject); procedure cbSmoothChange(Sender: TObject); - procedure CreateData; + procedure CreateDataForDerivative; + procedure CreateDataForSorting; procedure seAccumulationRangeChange(Sender: TObject); procedure FormCreate(Sender: TObject); procedure rgDataShapeClick(Sender: TObject); + procedure UserDefinedChartSourceGetChartDataItem( + ASource: TUserDefinedChartSource; AIndex: Integer; + var AItem: TChartDataItem); + private + FDataForSorting: array of TDataForSorting; end; var @@ -78,6 +99,19 @@ begin TChartAccumulationDirection(cbAccDirDerivative.ItemIndex); end; +procedure TForm1.btnSortClick(Sender: TObject); +begin + SortedChartSource.Sorted := not SortedChartSource.Sorted; +end; + +procedure TForm1.BubbleChartAfterPaint(ASender: TChart); +begin + if SortedChartSource.IsSorted then + lblSortInfo.Caption := 'Sorted by radius (descending)' + else + lblSortInfo.Caption := 'Not sorted'; +end; + procedure TForm1.cbAccDirStatisticsChange(Sender: TObject); begin ccsAvg.AccumulationDirection := @@ -98,7 +132,7 @@ begin ccsDerivative.AccumulationMethod := camDerivative; end; -procedure TForm1.CreateData; +procedure TForm1.CreateDataForDerivative; const N = 100; MIN_X = -10; @@ -128,15 +162,58 @@ begin end; end; +procedure TForm1.CreateDataForSorting; + + procedure AddCity(AYear: Integer; const ACityName: string; + ANumberOfVisitors: Integer; AColor: TChartColor); + begin + SetLength(FDataForSorting, Length(FDataForSorting) + 1); + with FDataForSorting[High(FDataForSorting)] do begin + Year := AYear; + CityName := ACityName; + Visitors := ANumberOfVisitors; + Color := AColor; + end; + end; + +begin + SetLength(FDataForSorting, 0); + AddCity(1967, 'City A', 155000, $00FFFF); // yellow + AddCity(1968, 'City B', 30000, $FF0000); // blue + AddCity(1969, 'City C', 450000, $FF00FF); // fuchsia + AddCity(1970, 'City D', 50000, $FFFF00); // aqua + AddCity(1971, 'City E', 80000, $00FF00); // lime + AddCity(1972, 'City F', 615000, $0000FF); // red + UserDefinedChartSource.PointsNumber := Length(FDataForSorting); + + { These settings are made in the Object Inspector for the SortedChartSource: + - Origin = UserDefinedChartSource + - SortBy = sbY + - SortIndex = 1 // --> sort by radius + - SortDir = sdDescending // --> draw large bubbles first + } +end; + procedure TForm1.FormCreate(Sender: TObject); begin Randomize; - CreateData; + CreateDataForDerivative; + CreateDataForSorting; end; procedure TForm1.rgDataShapeClick(Sender: TObject); begin - CreateData; + CreateDataForDerivative; +end; + +procedure TForm1.UserDefinedChartSourceGetChartDataItem( + ASource: TUserDefinedChartSource; AIndex: Integer; var AItem: TChartDataItem); +begin + AItem.X := FDataForSorting[AIndex].Year; + AItem.Y := 0; + AItem.YList[0] := Sqrt(FDataForSorting[AIndex].Visitors/100000 / PI); + AItem.Text := FDataForSorting[AIndex].CityName; + AItem.Color := FDataForSorting[AIndex].Color; end; procedure TForm1.seAccumulationRangeChange(Sender: TObject);