unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs,StdCtrls,TAGraph,TATools, TAChartAxis, TAChartAxisUtils, LCLType, math;
type
{ TForm1 }
TForm1 = class(TForm)
Chart1:TChart;
ChartToolset1:TChartToolset;
ChartToolset1AxisClickTool1:TAxisClickTool;
Label1:TLabel;
Memo1:TMemo;
procedure ChartToolset1AxisClickTool1Click(ASender:TChartTool;Axis:TChartAxis;AHitInfo:TChartAxisHitTests);
procedure FormCreate(Sender:TObject);
procedure Memo1KeyDown(Sender:TObject;var Key:Word;Shift:TShiftState);
private
FClickedAxis : TChartAxis;
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.ChartToolset1AxisClickTool1Click(ASender:TChartTool;Axis:TChartAxis;AHitInfo:TChartAxisHitTests);
var
s, sp: String;
i: Integer;
begin
FClickedAxis := Axis;
Memo1.Top := Chart1.top + Axis.TitlePolygon[0].Y;
Memo1.Height := Axis.TitlePolygon[1].Y - Axis.TitlePolygon[0].Y +1;
Memo1.left := Chart1.ClipRect.Left + Chart1.Left;
Memo1.Width := Chart1.Width - Chart1.ClipRect.Left - Chart1.MarginsExternal.right;
Memo1.Font := Axis.Title.LabelFont;
memo1.Text := Axis.Title.Caption;
Memo1.Visible := true;
end;
procedure TForm1.FormCreate(Sender:TObject);
var
i: integer;
begin
Chart1.Toolset := ChartToolset1;
chart1.AxisList.Add;
chart1.AxisList.Add;
chart1.AxisList.Add;
chart1.AxisList.Add;
for i:= 0 to chart1.AxisList.Count -1 do
begin
chart1.AxisList[i].Title.Visible := True;
chart1.AxisList[i].Title.Caption := 'Axis ' + IntToStr(i);
if i mod 2 = 0 then
begin
chart1.AxisList[i].Title.LabelFont.Orientation := 900;
chart1.AxisList[i].Alignment := calLeft;
end
else
begin
chart1.AxisList[i].Title.LabelFont.Orientation := 0;
chart1.AxisList[i].Alignment := calbottom;
end;
end;
chart1.AxisList[3].Title.Caption := chart1.AxisList[2].Title.Caption + 'abc' + LineEnding + '456';
Memo1.Alignment := taCenter;
memo1.WordWrap := False;
end;
function GetMemoLineHeight(AMemo: TMemo): Integer;
var
Bitmap: TBitmap;
begin
Bitmap := TBitmap.Create;
try
Bitmap.Canvas.Font.Assign(AMemo.Font);
// Measure a standard character
Result := Bitmap.Canvas.TextHeight('Wg');
finally
Bitmap.Free;
end;
end;
procedure TForm1.Memo1KeyDown(Sender:TObject;var Key:Word;Shift:TShiftState);
var
FontHeight : integer = 14;
begin
FontHeight := abs(GetFontData(Memo1.Font.Handle).Height);
if (Key = VK_ESCAPE) then
begin
Memo1.Visible := false;
Exit;
end;
if ((Key = VK_RETURN) and (ssCtrl in Shift)) then
begin
FClickedAxis.Title.Caption := Memo1.Text;
Memo1.Visible := false;
exit;
end;
if ((key = LCLtype.VK_RETURN) and (shift = [])) then
begin
Memo1.Height := min (FontHeight*3+8,Memo1.Height + FontHeight+4); //The first line starts 5 pixels below the top of the memo (in Windows)
Memo1.top := chart1.top+ FClickedAxis.TitlePolygon[0].Y - Memo1.Height + FontHeight+2;
end;
end;
end.