mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-19 02:29:35 +01:00
TAChart: Add user-drawn legend item to the legend demo
git-svn-id: trunk@27556 -
This commit is contained in:
parent
09b0ea83ae
commit
643fc88dfa
@ -1,11 +1,12 @@
|
||||
object Form1: TForm1
|
||||
Left = 328
|
||||
Left = 1322
|
||||
Height = 361
|
||||
Top = 151
|
||||
Top = 181
|
||||
Width = 510
|
||||
Caption = 'Form1'
|
||||
ClientHeight = 361
|
||||
ClientWidth = 510
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '0.9.29'
|
||||
object Chart1: TChart
|
||||
Left = 0
|
||||
@ -53,6 +54,16 @@ object Form1: TForm1
|
||||
Exploded = True
|
||||
Source = ListChartSource2
|
||||
end
|
||||
object Chart1FuncSeries1: TFuncSeries
|
||||
Extent.XMax = 5
|
||||
Extent.UseXMin = True
|
||||
Extent.UseXMax = True
|
||||
OnCalculate = Chart1FuncSeries1Calculate
|
||||
OnDrawLegend = Chart1FuncSeries1DrawLegend
|
||||
Pen.Color = clPurple
|
||||
Pen.Width = 2
|
||||
Title = 'Function'
|
||||
end
|
||||
end
|
||||
object pnControls: TPanel
|
||||
Left = 0
|
||||
|
||||
@ -5,7 +5,7 @@ unit main;
|
||||
interface
|
||||
|
||||
uses
|
||||
ExtCtrls, Spin, StdCtrls, Forms, TAGraph, TASeries, TASources, Classes;
|
||||
ExtCtrls, Spin, StdCtrls, Forms, TAGraph, TASeries, TASources, Classes, TALegend, Graphics;
|
||||
|
||||
type
|
||||
|
||||
@ -14,6 +14,7 @@ type
|
||||
TForm1 = class(TForm)
|
||||
Chart1: TChart;
|
||||
Chart1AreaSeries1: TAreaSeries;
|
||||
Chart1FuncSeries1: TFuncSeries;
|
||||
Chart1LineSeries1: TLineSeries;
|
||||
Chart1PieSeries1: TPieSeries;
|
||||
cbUseSidebar: TCheckBox;
|
||||
@ -31,6 +32,8 @@ type
|
||||
seSymbolWidth: TSpinEdit;
|
||||
seMarginY: TSpinEdit;
|
||||
procedure cbUseSidebarChange(Sender: TObject);
|
||||
procedure Chart1FuncSeries1Calculate(const AX: Double; out AY: Double);
|
||||
procedure Chart1FuncSeries1DrawLegend(ACanvas: TCanvas; const ARect: TRect);
|
||||
procedure rgAlignmentClick(Sender: TObject);
|
||||
procedure seMarginXChange(Sender: TObject);
|
||||
procedure seMarginYChange(Sender: TObject);
|
||||
@ -45,9 +48,6 @@ implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
uses
|
||||
TALegend;
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
procedure TForm1.cbUseSidebarChange(Sender: TObject);
|
||||
@ -55,6 +55,26 @@ begin
|
||||
Chart1.Legend.UseSidebar := cbUseSidebar.Checked;
|
||||
end;
|
||||
|
||||
procedure TForm1.Chart1FuncSeries1Calculate(const AX: Double; out AY: Double);
|
||||
begin
|
||||
AY := Sin(AX * 2) + 7;
|
||||
end;
|
||||
|
||||
procedure TForm1.Chart1FuncSeries1DrawLegend(
|
||||
ACanvas: TCanvas; const ARect: TRect);
|
||||
var
|
||||
x, y0, w: Integer;
|
||||
begin
|
||||
ACanvas.Pen := Chart1FuncSeries1.Pen;
|
||||
y0 := (ARect.Top + ARect.Bottom) div 2;
|
||||
ACanvas.MoveTo(ARect.Left, y0);
|
||||
w := ARect.Right - ARect.Left;
|
||||
for x := 0 to w do
|
||||
ACanvas.LineTo(
|
||||
ARect.Left + x,
|
||||
Round(Sin(x / w * 2 * Pi) * (ARect.Bottom - ARect.Top) / 2) + y0);
|
||||
end;
|
||||
|
||||
procedure TForm1.rgAlignmentClick(Sender: TObject);
|
||||
begin
|
||||
with Chart1.Legend do
|
||||
|
||||
Loading…
Reference in New Issue
Block a user