From f1cfea45dcf983e76fdcb6d0d4184c4e3449438f Mon Sep 17 00:00:00 2001 From: ask Date: Wed, 22 Jun 2011 14:13:21 +0000 Subject: [PATCH] TAChart: Add combobox with legend items to the legend demo git-svn-id: trunk@31335 - --- components/tachart/demo/legend/main.lfm | 19 ++++++++++-- components/tachart/demo/legend/main.pas | 40 +++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/components/tachart/demo/legend/main.lfm b/components/tachart/demo/legend/main.lfm index a7a26f52df..485b3bfabc 100644 --- a/components/tachart/demo/legend/main.lfm +++ b/components/tachart/demo/legend/main.lfm @@ -6,6 +6,8 @@ object Form1: TForm1 Caption = 'Form1' ClientHeight = 390 ClientWidth = 510 + OnCreate = FormCreate + OnDestroy = FormDestroy Position = poScreenCenter LCLVersion = '0.9.31' object Chart1: TChart @@ -15,12 +17,14 @@ object Form1: TForm1 Width = 510 AxisList = < item - Title.LabelFont.Orientation = 900 Visible = False + Minors = <> + Title.LabelFont.Orientation = 900 end item - Alignment = calBottom Visible = False + Alignment = calBottom + Minors = <> end> BackColor = clSkyBlue Foot.Brush.Color = clBtnFace @@ -192,6 +196,17 @@ object Form1: TForm1 TabOrder = 5 Value = 4 end + object cbSeries: TComboBox + Left = 102 + Height = 19 + Top = 60 + Width = 148 + ItemHeight = 16 + OnDrawItem = cbSeriesDrawItem + ReadOnly = True + Style = csOwnerDrawFixed + TabOrder = 6 + end end object RandomChartSource1: TRandomChartSource PointsNumber = 7 diff --git a/components/tachart/demo/legend/main.pas b/components/tachart/demo/legend/main.pas index 92ba2a540f..3393b675f1 100644 --- a/components/tachart/demo/legend/main.pas +++ b/components/tachart/demo/legend/main.pas @@ -5,8 +5,8 @@ unit main; interface uses - ExtCtrls, Spin, StdCtrls, Forms, TAGraph, TASeries, TASources, Classes, - TALegend, TAFuncSeries, Graphics; + Contnrs, Controls, ExtCtrls, Graphics, Spin, StdCtrls, Forms, + TAGraph, TASeries, TASources, Classes, TALegend, TAFuncSeries; type @@ -19,6 +19,7 @@ type Chart1LineSeries1: TLineSeries; Chart1PieSeries1: TPieSeries; cbUseSidebar: TCheckBox; + cbSeries: TComboBox; lblSpacing: TLabel; lblMarginX: TLabel; lblSymbolWidth: TLabel; @@ -32,15 +33,21 @@ type seMarginX: TSpinEdit; seSymbolWidth: TSpinEdit; seMarginY: TSpinEdit; + procedure cbSeriesDrawItem(Control: TWinControl; Index: Integer; + ARect: TRect; State: TOwnerDrawState); procedure cbUseSidebarChange(Sender: TObject); procedure Chart1FuncSeries1Calculate(const AX: Double; out AY: Double); procedure Chart1FuncSeries1DrawLegend( ACanvas: TCanvas; const ARect: TRect; AIndex: Integer; var AText: String); + procedure FormCreate(Sender: TObject); + procedure FormDestroy(Sender: TObject); procedure rgAlignmentClick(Sender: TObject); procedure seMarginXChange(Sender: TObject); procedure seMarginYChange(Sender: TObject); procedure seSpacingChange(Sender: TObject); procedure seSymbolWidthChange(Sender: TObject); + private + FItems: TObjectList; end; var @@ -51,10 +58,23 @@ implementation {$R *.lfm} uses - SysUtils; + SysUtils, TADrawerCanvas, TADrawUtils; { TForm1 } +procedure TForm1.cbSeriesDrawItem( + Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState); +var + id: IChartDrawer; + r: TRect; +begin + id := TCanvasDrawer.Create(cbSeries.Canvas); + r := Bounds( + ARect.Left, ARect.Top, Chart1.Legend.SymbolWidth, cbSeries.ItemHeight); + id.Pen := Chart1.Legend.Frame; + (FItems[Index] as TLegendItem).Draw(id, r); +end; + procedure TForm1.cbUseSidebarChange(Sender: TObject); begin Chart1.Legend.UseSidebar := cbUseSidebar.Checked; @@ -81,6 +101,20 @@ begin Round(Sin(x / w * 2 * Pi) * (ARect.Bottom - ARect.Top) / 2) + y0); end; +procedure TForm1.FormCreate(Sender: TObject); +var + i: Integer; +begin + FItems := Chart1.GetLegendItems; + for i := 1 to FItems.Count do + cbSeries.AddItem('', nil); +end; + +procedure TForm1.FormDestroy(Sender: TObject); +begin + FreeAndNil(FItems); +end; + procedure TForm1.rgAlignmentClick(Sender: TObject); begin with Chart1.Legend do