TAChart: Add chart title demo project.

This commit is contained in:
wp_xyz 2022-12-10 23:54:16 +01:00
parent 8b2c86f689
commit 2880e3bdde
4 changed files with 533 additions and 0 deletions

View File

@ -0,0 +1,296 @@
object MainForm: TMainForm
Left = 828
Height = 405
Top = 332
Width = 537
AutoSize = True
Caption = 'Chart Title Demo'
ClientHeight = 405
ClientWidth = 537
OnActivate = FormActivate
LCLVersion = '2.3.0.0'
object Chart1: TChart
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner
AnchorSideRight.Control = rgAlignment
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 16
Height = 373
Top = 16
Width = 300
AxisList = <
item
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'y axis'
Title.LabelBrush.Style = bsClear
end
item
Alignment = calBottom
Marks.LabelBrush.Style = bsClear
Minors = <>
Title.Visible = True
Title.Caption = 'x axis'
Title.LabelBrush.Style = bsClear
end>
Title.Brush.Color = clMenuHighlight
Title.Font.Color = clWindow
Title.Font.Height = -16
Title.Font.Style = [fsBold]
Title.Text.Strings = (
'Chart Title'
)
Title.Visible = True
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Around = 16
Constraints.MinWidth = 300
end
object cbFullWidth: TCheckBox
AnchorSideLeft.Control = rgAlignment
AnchorSideTop.Control = gbTitleMargins
AnchorSideTop.Side = asrBottom
Left = 328
Height = 19
Top = 308
Width = 93
BorderSpacing.Top = 16
Caption = 'Title full width'
OnChange = cbFullWidthChange
TabOrder = 5
end
object mmoTitleText: TMemo
AnchorSideLeft.Control = rgAlignment
AnchorSideTop.Control = lblTitleText
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = rgAlignment
AnchorSideRight.Side = asrBottom
Left = 328
Height = 48
Top = 41
Width = 187
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 2
BorderSpacing.Right = 6
Lines.Strings = (
'Chart Title'
)
OnChange = mmoTitleTextChange
TabOrder = 1
end
object cbShowAxisMarksAndTitle: TCheckBox
AnchorSideLeft.Control = rgAlignment
AnchorSideTop.Control = cbFullWidth
AnchorSideTop.Side = asrBottom
Left = 328
Height = 19
Top = 333
Width = 151
BorderSpacing.Top = 6
Caption = 'Show axis marks and title'
Checked = True
OnChange = cbShowAxisMarksAndTitleChange
State = cbChecked
TabOrder = 6
end
object rgAlignment: TRadioGroup
AnchorSideTop.Control = cbShape
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 328
Height = 51
Top = 149
Width = 193
Anchors = [akTop, akRight]
AutoFill = True
AutoSize = True
BorderSpacing.Top = 12
BorderSpacing.Right = 16
Caption = 'Alignment'
ChildSizing.LeftRightSpacing = 18
ChildSizing.TopBottomSpacing = 6
ChildSizing.HorizontalSpacing = 12
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 3
ClientHeight = 31
ClientWidth = 189
Columns = 3
ItemIndex = 1
Items.Strings = (
'left'
'center'
'right'
)
OnClick = rgAlignmentClick
TabOrder = 3
end
object gbTitleMargins: TGroupBox
AnchorSideLeft.Control = rgAlignment
AnchorSideTop.Control = rgAlignment
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = rgAlignment
AnchorSideRight.Side = asrBottom
Left = 328
Height = 80
Top = 212
Width = 193
Anchors = [akTop, akLeft, akRight]
AutoSize = True
BorderSpacing.Top = 12
Caption = 'Margins'
ClientHeight = 60
ClientWidth = 189
TabOrder = 4
object Label1: TLabel
AnchorSideLeft.Control = gbTitleMargins
AnchorSideTop.Control = gbTitleMargins
Left = 16
Height = 15
Top = 8
Width = 20
BorderSpacing.Left = 16
BorderSpacing.Top = 8
Caption = 'Left'
end
object Label2: TLabel
AnchorSideTop.Control = Label1
AnchorSideRight.Control = gbTitleMargins
AnchorSideRight.Side = asrBottom
Left = 145
Height = 15
Top = 8
Width = 28
Alignment = taRightJustify
Anchors = [akTop, akRight]
BorderSpacing.Right = 16
Caption = 'Right'
end
object seLeftMargin: TSpinEdit
AnchorSideLeft.Control = Label1
AnchorSideTop.Control = Label1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Bevel1
Left = 16
Height = 23
Top = 25
Width = 67
Alignment = taRightJustify
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 2
BorderSpacing.Bottom = 12
OnChange = seLeftMarginChange
TabOrder = 0
Value = 4
end
object seRightMargin: TSpinEdit
AnchorSideLeft.Control = Bevel1
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = seLeftMargin
AnchorSideRight.Control = Label2
AnchorSideRight.Side = asrBottom
Left = 106
Height = 23
Top = 25
Width = 67
Alignment = taRightJustify
Anchors = [akTop, akLeft, akRight]
OnChange = seRightMarginChange
TabOrder = 1
Value = 4
end
object Bevel1: TBevel
AnchorSideLeft.Control = gbTitleMargins
AnchorSideLeft.Side = asrCenter
Left = 83
Height = 30
Top = 8
Width = 23
Shape = bsSpacer
end
end
object cbShape: TComboBox
AnchorSideLeft.Control = rgAlignment
AnchorSideTop.Control = lblShape
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = rgAlignment
AnchorSideRight.Side = asrBottom
Left = 328
Height = 23
Top = 114
Width = 187
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 2
BorderSpacing.Right = 6
ItemHeight = 15
ItemIndex = 0
Items.Strings = (
'Rectangle'
'Ellipse'
'RoundRect'
'RoundSide'
'Userdefined (Rhomboid)'
)
OnChange = cbShapeChange
Style = csDropDownList
TabOrder = 2
Text = 'Rectangle'
end
object lblTitleText: TLabel
AnchorSideLeft.Control = rgAlignment
AnchorSideTop.Control = Chart1
Left = 328
Height = 15
Top = 24
Width = 45
BorderSpacing.Top = 8
Caption = 'Title text'
end
object lblShape: TLabel
AnchorSideLeft.Control = rgAlignment
AnchorSideTop.Control = mmoTitleText
AnchorSideTop.Side = asrBottom
Left = 328
Height = 15
Top = 97
Width = 32
BorderSpacing.Top = 8
Caption = 'Shape'
end
object cbFrame: TCheckBox
AnchorSideLeft.Control = rgAlignment
AnchorSideTop.Control = cbShowAxisMarksAndTitle
AnchorSideTop.Side = asrBottom
Left = 328
Height = 19
Top = 358
Width = 74
BorderSpacing.Top = 6
BorderSpacing.Bottom = 16
Caption = 'Title frame'
OnChange = cbFrameChange
TabOrder = 7
end
object clbFrameColor: TColorButton
AnchorSideLeft.Control = cbFrame
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = cbFrame
AnchorSideTop.Side = asrCenter
Left = 410
Height = 25
Top = 355
Width = 29
BorderSpacing.Left = 8
BorderSpacing.Bottom = 16
BorderWidth = 2
ButtonColorSize = 16
ButtonColor = clBlack
OnColorChanged = clbFrameColorColorChanged
end
end

View File

@ -0,0 +1,135 @@
unit main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
Spin, TAGraph, TATextElements, Types, TAChartUtils, TASeries;
type
{ TMainForm }
TMainForm = class(TForm)
Bevel1: TBevel;
Chart1: TChart;
cbFullWidth: TCheckBox;
cbShowAxisMarksAndTitle: TCheckBox;
cbShape: TComboBox;
cbFrame: TCheckBox;
clbFrameColor: TColorButton;
gbTitleMargins: TGroupBox;
Label1: TLabel;
Label2: TLabel;
lblTitleText: TLabel;
lblShape: TLabel;
mmoTitleText: TMemo;
rgAlignment: TRadioGroup;
seLeftMargin: TSpinEdit;
seRightMargin: TSpinEdit;
procedure cbFrameChange(Sender: TObject);
procedure Chart1ChartTitleGetShape(ASender: TChartTextElement;
const ABoundingBox: TRect; var APolygon: TPointArray);
procedure cbFullWidthChange(Sender: TObject);
procedure cbShowAxisMarksAndTitleChange(Sender: TObject);
procedure cbShapeChange(Sender: TObject);
procedure clbFrameColorColorChanged(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure mmoTitleTextChange(Sender: TObject);
procedure rgAlignmentClick(Sender: TObject);
procedure seLeftMarginChange(Sender: TObject);
procedure seRightMarginChange(Sender: TObject);
private
public
end;
var
MainForm: TMainForm;
implementation
{$R *.lfm}
{ TMainForm }
procedure TMainForm.mmoTitleTextChange(Sender: TObject);
begin
Chart1.Title.Text.Text := mmoTitleText.Lines.Text;
end;
procedure TMainForm.rgAlignmentClick(Sender: TObject);
begin
case rgAlignment.ItemIndex of
0: Chart1.Title.Alignment := taLeftJustify;
1: Chart1.Title.Alignment := taCenter;
2: Chart1.Title.Alignment := taRightJustify;
end;
end;
procedure TMainForm.seLeftMarginChange(Sender: TObject);
begin
Chart1.Title.Margins.Left := seLeftMargin.Value;
end;
procedure TMainForm.seRightMarginChange(Sender: TObject);
begin
Chart1.Title.Margins.Right := seRightMargin.Value;
end;
procedure TMainForm.cbFullWidthChange(Sender: TObject);
begin
Chart1.Title.FullWidth := cbFullWidth.Checked;
end;
procedure TMainForm.Chart1ChartTitleGetShape(ASender: TChartTextElement;
const ABoundingBox: TRect; var APolygon: TPointArray);
var
delta: Integer;
begin
delta := ABoundingBox.Height div 2;
SetLength(APolygon, 4);
APolygon[0] := Point(ABoundingBox.Left + delta, ABoundingBox.Top);
APolygon[1] := Point(ABoundingBox.Right, ABoundingBox.Top);
APolygon[2] := Point(ABoundingBox.Right - delta, ABoundingBox.Bottom);
APolygon[3] := Point(ABoundingBox.Left, ABoundingBox.Bottom);
end;
procedure TMainForm.cbFrameChange(Sender: TObject);
begin
Chart1.Title.Frame.Visible := cbFrame.Checked;
end;
procedure TMainForm.cbShowAxisMarksAndTitleChange(Sender: TObject);
begin
Chart1.BottomAxis.Marks.Visible := cbShowAxisMarksAndTitle.Checked;
Chart1.BottomAxis.Title.Visible := cbShowAxisMarksAndTitle.Checked;
Chart1.LeftAxis.Marks.Visible := cbShowAxisMarksAndTitle.Checked;
Chart1.LeftAxis.Title.Visible := cbShowAxisMarksAndTitle.Checked;
end;
procedure TMainForm.cbShapeChange(Sender: TObject);
begin
Chart1.Title.Shape := TChartLabelShape(cbShape.ItemIndex);
if Chart1.Title.Shape = clsUserDefined then
Chart1.Title.OnGetShape := @Chart1ChartTitleGetShape
else
Chart1.Title.OnGetShape := nil;
end;
procedure TMainForm.clbFrameColorColorChanged(Sender: TObject);
begin
Chart1.Title.Frame.Color := clbFrameColor.ButtonColor;
end;
procedure TMainForm.FormActivate(Sender: TObject);
begin
Constraints.MinWidth := Width;
Constraints.MinHeight := Height;
end;
end.

View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<SessionStorage Value="InProjectDir"/>
<Title Value="title_demo"/>
<Scaled Value="True"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<XPManifest>
<DpiAware Value="True"/>
</XPManifest>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<RequiredPackages>
<Item>
<PackageName Value="TAChartLazarusPkg"/>
</Item>
<Item>
<PackageName Value="LCL"/>
</Item>
</RequiredPackages>
<Units>
<Unit>
<Filename Value="title_demo.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="main.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="MainForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="title_demo"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,25 @@
program title_demo;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
{$IFDEF HASAMIGA}
athreads,
{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, main, tachartlazaruspkg
{ you can add units after this };
{$R *.res}
begin
RequireDerivedFormResource:=True;
Application.Scaled:=True;
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.