File: unit1.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (141 lines) | stat: -rw-r--r-- 3,615 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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.