mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-03 11:20:23 +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'
|
Caption = 'Form1'
|
||||||
ClientHeight = 390
|
ClientHeight = 390
|
||||||
ClientWidth = 510
|
ClientWidth = 510
|
||||||
|
OnCreate = FormCreate
|
||||||
|
OnDestroy = FormDestroy
|
||||||
Position = poScreenCenter
|
Position = poScreenCenter
|
||||||
LCLVersion = '0.9.31'
|
LCLVersion = '0.9.31'
|
||||||
object Chart1: TChart
|
object Chart1: TChart
|
||||||
@ -15,12 +17,14 @@ object Form1: TForm1
|
|||||||
Width = 510
|
Width = 510
|
||||||
AxisList = <
|
AxisList = <
|
||||||
item
|
item
|
||||||
Title.LabelFont.Orientation = 900
|
|
||||||
Visible = False
|
Visible = False
|
||||||
|
Minors = <>
|
||||||
|
Title.LabelFont.Orientation = 900
|
||||||
end
|
end
|
||||||
item
|
item
|
||||||
Alignment = calBottom
|
|
||||||
Visible = False
|
Visible = False
|
||||||
|
Alignment = calBottom
|
||||||
|
Minors = <>
|
||||||
end>
|
end>
|
||||||
BackColor = clSkyBlue
|
BackColor = clSkyBlue
|
||||||
Foot.Brush.Color = clBtnFace
|
Foot.Brush.Color = clBtnFace
|
||||||
@ -192,6 +196,17 @@ object Form1: TForm1
|
|||||||
TabOrder = 5
|
TabOrder = 5
|
||||||
Value = 4
|
Value = 4
|
||||||
end
|
end
|
||||||
|
object cbSeries: TComboBox
|
||||||
|
Left = 102
|
||||||
|
Height = 19
|
||||||
|
Top = 60
|
||||||
|
Width = 148
|
||||||
|
ItemHeight = 16
|
||||||
|
OnDrawItem = cbSeriesDrawItem
|
||||||
|
ReadOnly = True
|
||||||
|
Style = csOwnerDrawFixed
|
||||||
|
TabOrder = 6
|
||||||
|
end
|
||||||
end
|
end
|
||||||
object RandomChartSource1: TRandomChartSource
|
object RandomChartSource1: TRandomChartSource
|
||||||
PointsNumber = 7
|
PointsNumber = 7
|
||||||
|
@ -5,8 +5,8 @@ unit main;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
ExtCtrls, Spin, StdCtrls, Forms, TAGraph, TASeries, TASources, Classes,
|
Contnrs, Controls, ExtCtrls, Graphics, Spin, StdCtrls, Forms,
|
||||||
TALegend, TAFuncSeries, Graphics;
|
TAGraph, TASeries, TASources, Classes, TALegend, TAFuncSeries;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -19,6 +19,7 @@ type
|
|||||||
Chart1LineSeries1: TLineSeries;
|
Chart1LineSeries1: TLineSeries;
|
||||||
Chart1PieSeries1: TPieSeries;
|
Chart1PieSeries1: TPieSeries;
|
||||||
cbUseSidebar: TCheckBox;
|
cbUseSidebar: TCheckBox;
|
||||||
|
cbSeries: TComboBox;
|
||||||
lblSpacing: TLabel;
|
lblSpacing: TLabel;
|
||||||
lblMarginX: TLabel;
|
lblMarginX: TLabel;
|
||||||
lblSymbolWidth: TLabel;
|
lblSymbolWidth: TLabel;
|
||||||
@ -32,15 +33,21 @@ type
|
|||||||
seMarginX: TSpinEdit;
|
seMarginX: TSpinEdit;
|
||||||
seSymbolWidth: TSpinEdit;
|
seSymbolWidth: TSpinEdit;
|
||||||
seMarginY: TSpinEdit;
|
seMarginY: TSpinEdit;
|
||||||
|
procedure cbSeriesDrawItem(Control: TWinControl; Index: Integer;
|
||||||
|
ARect: TRect; State: TOwnerDrawState);
|
||||||
procedure cbUseSidebarChange(Sender: TObject);
|
procedure cbUseSidebarChange(Sender: TObject);
|
||||||
procedure Chart1FuncSeries1Calculate(const AX: Double; out AY: Double);
|
procedure Chart1FuncSeries1Calculate(const AX: Double; out AY: Double);
|
||||||
procedure Chart1FuncSeries1DrawLegend(
|
procedure Chart1FuncSeries1DrawLegend(
|
||||||
ACanvas: TCanvas; const ARect: TRect; AIndex: Integer; var AText: String);
|
ACanvas: TCanvas; const ARect: TRect; AIndex: Integer; var AText: String);
|
||||||
|
procedure FormCreate(Sender: TObject);
|
||||||
|
procedure FormDestroy(Sender: TObject);
|
||||||
procedure rgAlignmentClick(Sender: TObject);
|
procedure rgAlignmentClick(Sender: TObject);
|
||||||
procedure seMarginXChange(Sender: TObject);
|
procedure seMarginXChange(Sender: TObject);
|
||||||
procedure seMarginYChange(Sender: TObject);
|
procedure seMarginYChange(Sender: TObject);
|
||||||
procedure seSpacingChange(Sender: TObject);
|
procedure seSpacingChange(Sender: TObject);
|
||||||
procedure seSymbolWidthChange(Sender: TObject);
|
procedure seSymbolWidthChange(Sender: TObject);
|
||||||
|
private
|
||||||
|
FItems: TObjectList;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -51,10 +58,23 @@ implementation
|
|||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
SysUtils;
|
SysUtils, TADrawerCanvas, TADrawUtils;
|
||||||
|
|
||||||
{ TForm1 }
|
{ 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);
|
procedure TForm1.cbUseSidebarChange(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
Chart1.Legend.UseSidebar := cbUseSidebar.Checked;
|
Chart1.Legend.UseSidebar := cbUseSidebar.Checked;
|
||||||
@ -81,6 +101,20 @@ begin
|
|||||||
Round(Sin(x / w * 2 * Pi) * (ARect.Bottom - ARect.Top) / 2) + y0);
|
Round(Sin(x / w * 2 * Pi) * (ARect.Bottom - ARect.Top) / 2) + y0);
|
||||||
end;
|
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);
|
procedure TForm1.rgAlignmentClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
with Chart1.Legend do
|
with Chart1.Legend do
|
||||||
|
Loading…
Reference in New Issue
Block a user