📄 labels.pas
字号:
unit Labels;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, OleCtrls, ChartfxLib_TLB,AXCtrls;
type
TForm1 = class(TForm)
ChartFX1: TChartFX;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
procedure FormActivate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
procedure ChartFX1GetPointLabel(Sender: TObject; nSerie: Smallint;
nPoint: Integer; var nRes: Smallint);
procedure CheckBox1Click(Sender: TObject);
procedure ChartFX1GetAxisLabel(Sender: TObject; nAxis: Smallint;
var nRes: Smallint);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormActivate(Sender: TObject);
var
i: Integer;
begin
// Initializa data
ChartFX1.OpenDataEx(COD_VALUES, 2, 10);
For i := 0 To 9 Do begin
ChartFX1.ValueEx[0, i] := 10 + Random(40);
ChartFX1.ValueEx[1, i] := 60 + Random(30);
end;
ChartFX1.CloseData(COD_VALUES);
// Enable Y-Axis notification events for advanced customization
ChartFX1.Axis[AXIS_Y].Style := ChartFX1.Axis[AXIS_Y].Style Or AS_NOTIFY;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
f: TFont;
begin
// assign each label
For i := 0 To 9 do
ChartFX1.Legend[i] := DateTimeToStr(Date + i);
// X Axis format
f := TFont.Create; // Init PASCAL Font
With ChartFX1.Axis[AXIS_X] do
begin
// set the text color of the x and y axis labels
TextColor := RGB(255, 255, 255);
// set the font properties for the x axis labels
SetOleFont(f, Font);
With f Do
begin
Style := [fsBold] + [fsItalic];
Size := 10;
Name := 'Times New Roman';
End;
// set the style in which the labels should display
Style := (Style Or AS_2LEVELS Or AS_CENTERED) And Not AS_LONGTICK;
End
end;
procedure TForm1.Button2Click(Sender: TObject);
VAR
i:Integer;
f: TFont;
s: String;
begin
// the interval between 2 consecutive tickmarks is equal to 10
ChartFX1.Axis[AXIS_Y].LabelValue := 10;
// assign each label
For i := 0 To 9 do begin
Str(i,s);
ChartFX1.Axis[AXIS_Y].Label_[i] := 'Label ' + s;
end;
f := TFont.Create; // Init PASCAL Font
With ChartFX1.Axis[AXIS_Y] Do Begin
// set the text color of the y axis labels
TextColor := RGB(255, 255, 255);
// set the font properties for the y axis labels
SetOleFont(f, Font);
With f do
begin
Style := [fsItalic];
Size := 10;
Name := 'Times New Roman';
End;
End;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
// show the point labels for all series
ChartFX1.PointLabels := True;
// set the font properties for the point labels
ChartFX1.PointLabelsFont.Name := 'Courier New';
ChartFX1.PointLabelsFont.Size := 8;
// set the text color for the point labels
ChartFX1.RGBFont[CHART_VALUESFT] := RGB(0, 0, 0);
//set the angle of the point labels
ChartFX1.Series[0].PointLabelAngle := -45;
ChartFX1.Series[1].PointLabelAngle := 45;
//set the point labels to be aligned to the left of the marker
ChartFX1.Series[0].PointLabelAlign := LA_RIGHT Or LA_TOP;
// set the point labels to be aligned to the right of the marker
ChartFX1.Series[1].PointLabelAlign := LA_LEFT Or LA_BASELINE;
end;
procedure TForm1.Button4Click(Sender: TObject);
VAR
f: TFont;
begin
// Y Axis title
f := TFont.Create; // Init PASCAL Font
With ChartFX1.Axis[AXIS_Y] do begin
Title := 'Y Axis Title';
TitleColor := RGB(255, 255, 255);
SetOleFont(f, TitleFont);
f.Style := [fsBold] + [fsItalic];
f.Name := 'Arial';
f.Size := 12;
End;
// X Axis title
With ChartFX1.Axis[AXIS_X] do begin
Title := 'X Axis Title';
TitleColor := RGB(255, 255, 255);
SetOleFont(f, TitleFont);
f.Style := [fsBold] + [fsItalic];
f.Name := 'Arial';
f.Size := 12;
End;
// Top title
ChartFX1.Title[CHART_TOPTIT] := 'Labels and Titles';
ChartFX1.Fonts[CHART_TOPTIT] := CF_BOLD Or CF_ITALIC Or 16;
ChartFX1.RGBFont[CHART_TOPTIT] := RGB(255, 255, 255);
end;
procedure TForm1.CheckBox2Click(Sender: TObject);
begin
ChartFX1.PointLabels := True;
ChartFX1.Refresh;
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
// Custom Y-Axis labels. Make room
If CheckBox1.State = cbChecked Then
ChartFX1.LeftGap := ChartFX1.LeftGap + 40
Else
ChartFX1.LeftGap := ChartFX1.LeftGap - 40
end;
procedure TForm1.ChartFX1GetPointLabel(Sender: TObject; nSerie: Smallint;
nPoint: Integer; var nRes: Smallint);
begin
// Custom point labels
If CheckBox2.State = cbChecked Then
begin
ChartFX1.HText := '#' + ChartFX1.HText + '#';
nRes := 1;
End;
end;
procedure TForm1.ChartFX1GetAxisLabel(Sender: TObject; nAxis: Smallint;
var nRes: Smallint);
begin
// Custom Y-Axis labels
If CheckBox1.State = cbChecked Then begin
ChartFX1.HText := 'Custom ' + ChartFX1.HText;
nRes := 1;
End
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -