mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-28 20:40:56 +02:00
TAChart: Add combobox with legend items to the legend demo
git-svn-id: trunk@31335 -
This commit is contained in:
parent
80521e30cc
commit
f1cfea45dc
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user