TAChart: Add demo for creation of a dual-axis-chart at runtime.

git-svn-id: trunk@54329 -
This commit is contained in:
wp 2017-03-02 23:12:18 +00:00
parent e425cc10ae
commit 0899cfc7a4
5 changed files with 285 additions and 0 deletions

4
.gitattributes vendored
View File

@ -4301,6 +4301,10 @@ components/tachart/demo/runtime/chartstyles/project1.lpr svneol=native#text/plai
components/tachart/demo/runtime/chartstyles/readme.txt svneol=native#text/plain
components/tachart/demo/runtime/chartstyles/unit1.lfm svneol=native#text/plain
components/tachart/demo/runtime/chartstyles/unit1.pas svneol=native#text/plain
components/tachart/demo/runtime/dualaxes/project1.lpi svneol=native#text/plain
components/tachart/demo/runtime/dualaxes/project1.lpr svneol=native#text/plain
components/tachart/demo/runtime/dualaxes/unit1.lfm svneol=native#text/plain
components/tachart/demo/runtime/dualaxes/unit1.pas svneol=native#text/plain
components/tachart/demo/runtime/plotunit/main.lfm svneol=native#text/plain
components/tachart/demo/runtime/plotunit/main.pas svneol=native#text/plain
components/tachart/demo/runtime/plotunit/plotdemo.lpi svneol=native#text/plain

View File

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="10"/>
<PathDelim Value="\"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="project1"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<Icon Value="0"/>
</General>
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
</RunParams>
<RequiredPackages Count="2">
<Item1>
<PackageName Value="TAChartLazarusPkg"/>
</Item1>
<Item2>
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="2">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
<Unit1>
<Filename Value="unit1.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="project1"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<UseExternalDbgSyms Value="True"/>
</Debugging>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,21 @@
program project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, Unit1, tachartlazaruspkg
{ you can add units after this };
{$R *.res}
begin
RequireDerivedFormResource := True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

View File

@ -0,0 +1,35 @@
object Form1: TForm1
Left = 280
Height = 331
Top = 130
Width = 505
Caption = 'Form1'
ClientHeight = 331
ClientWidth = 505
OnCreate = FormCreate
LCLVersion = '1.7'
object Chart1: TChart
Left = 0
Height = 331
Top = 0
Width = 505
AxisList = <
item
Minors = <>
Title.LabelFont.Orientation = 900
end
item
Alignment = calBottom
Minors = <>
end>
BackColor = clWhite
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
end
end

View File

@ -0,0 +1,141 @@
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, TAGraph, Forms,
Controls, Graphics, Dialogs;
type
{ TForm1 }
TForm1 = class(TForm)
Chart1: TChart;
procedure FormCreate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
uses
TAChartAxis, TAChartAxisUtils, TALegend, TATransformations, TASeries;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
const
LEFT_COLOR = clRed;
RIGHT_COLOR = clBlue;
var
leftAxis, rightAxis: TChartAxis;
t: TAutoscaleAxisTransform;
leftSeries, rightSeries: TLineSeries;
i: Integer;
axis: TChartAxis;
begin
{ *** Left axis *** }
// It is already created, but we set some properties
leftAxis := Chart1.LeftAxis;
leftAxis.Marks.LabelFont.Color := LEFT_COLOR;
leftAxis.Title.LabelFont.Color := LEFT_COLOR;
leftAxis.Title.Caption := 'Left axis';
leftAxis.Title.Visible := true;
leftAxis.AxisPen.Color := LEFT_COLOR;
leftAxis.AxisPen.Visible := true;
leftAxis.TickColor := LEFT_COLOR;
// Draw marks and axis title at the data part of the axis
leftAxis.Marks.AtDataOnly := true;
leftAxis.AtDataOnly := true;
leftAxis.Title.PositionOnMarks := true;
// AxisTransformation for left axis
Chart1.LeftAxis.Transformations := TChartAxisTransformations.Create(self);
t := TAutoscaleAxisTransform.Create(Chart1.LeftAxis.Transformations);
t.Transformations := Chart1.LeftAxis.Transformations;
t.MinValue := 0;
t.MaxValue := 0.5;
// Series for left axis
leftSeries := TLineSeries.Create(Chart1);
leftSeries.SeriesColor := LEFT_COLOR;
leftSeries.Title := 'red (left)';
leftSeries.AxisIndexY := Chart1.LeftAxis.Index;
for i:=0 to 10 do
leftSeries.AddXY(i, random);
Chart1.AddSeries(leftSeries);
{ *** Right axis *** }
rightAxis := Chart1.AxisList.Add;
rightAxis.Alignment := calRight;
rightAxis.Title.Caption := 'Right axis';
rightAxis.Title.Visible := true;
rightAxis.Marks.LabelFont.Color := RIGHT_COLOR;
rightAxis.Title.LabelFont.Color := RIGHT_COLOR;
rightAxis.Title.LabelFont.Orientation := -900; // in 1/10 degrees
rightAxis.AxisPen.Color := RIGHT_COLOR;
rightAxis.AxisPen.Visible := true;
rightAxis.TickColor := RIGHT_COLOR;
// Draw marks and axis title at the data part of the axis
rightAxis.Marks.AtDataOnly := true;
rightAxis.AtDataOnly := true;
rightAxis.Title.PositionOnMarks := true;
// Axis transformation for right axis
rightAxis.Transformations := TChartAxisTransformations.Create(self);
t := TAutoscaleAxisTransform.Create(rightAxis.Transformations);
t.MinValue := 0.5;
t.MaxValue := 1.0;
t.Transformations := rightAxis.Transformations;
// Series for right axis
rightSeries := TLineSeries.Create(Chart1);
rightSeries.SeriesColor := RIGHT_COLOR;
rightSeries.Title := 'blue (right)';
rightSeries.AxisIndexY := rightAxis.Index;
for i:=5 to 20 do
rightSeries.AddXY(i, random*10);
Chart1.AddSeries(rightSeries);
// Second series for right axis
rightSeries := TLineSeries.Create(Chart1);
rightSeries.SeriesColor := RIGHT_COLOR;
rightSeries.LinePen.Style := psDot;
rightSeries.Title := 'blue dotted (right)';
rightSeries.AxisIndexY := rightAxis.Index;
for i:=3 to 15 do
rightSeries.AddXY(i, random*12 + 5);
Chart1.AddSeries(rightSeries);
{ *** Misc *** }
// Show legend
Chart1.Legend.Visible := true;
Chart1.Legend.Alignment := laBottomCenter;
Chart1.Legend.ColumnCount := 3;
// Axis grids
for axis in Chart1.AxisList do begin
axis.Grid.Style := psSolid;
axis.Grid.Color := $E0E0E0;
end;
end;
end.