unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs,StdCtrls,
Types, math,
TAGraph,TASeries,TATools,TATransformations, TAChartAxis, TACustomSource;
type
{ TForm1 }
TForm1 = class(TForm)
Button1:TButton;
Chart1:TChart;
Chart1LineSeries1:TLineSeries;
Chart1LineSeries2:TLineSeries;
ChartAxisTransformationsBottom:TChartAxisTransformations;
AutoBottom:TAutoScaleAxisTransform;
AutoLeft:TAutoScaleAxisTransform;
CumuBottom:TCumulNormDistrAxisTransform;
CumulLeft:TCumulNormDistrAxisTransform;
LogarithmBottom:TLogarithmAxisTransform;
LogarithmLeft:TLogarithmAxisTransform;
LinearBottom:TLinearAxisTransform;
ChartAxisTransformationsLeft:TChartAxisTransformations;
LinearLeft:TLinearAxisTransform;
procedure Button1Click(Sender:TObject);
procedure FormCreate(Sender:TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure HighlightFirstAndLastAxisLabels(Axis: TChartAxis);
procedure DrawLabelBorder(AIndex: Integer; AColor: TColor);
var
R: TRect;
vt: TChartValueText;
begin
if AIndex = -1 then
exit;
vt := Axis.Value[AIndex];
if Length(vt.FPolygon) = 0 then
exit;
R.TopLeft := vt.FPolygon[0];
R.BottomRight := vt.FPolygon[2];
Types.InflateRect(R, 4, 2);
Axis.Drawer.SetPenParams(psSolid, AColor);
Axis.Drawer.Rectangle(R);
end;
begin
Axis.Drawer.SetBrushParams(bsClear, clNone);
// Find first label which is on the axis and mark it by a green border
DrawLabelBorder(Axis.GetIndexOfFirstVisibleMark, clLime);
// Find last label which is on the axis and mark it by a red border
DrawLabelBorder(Axis.GetIndexOfLastVisibleMark, clRed);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
x, y: Double;
begin
for i := -100 to 100 do
begin
x := i / 10;
y := 1.0 / (1.0 + exp(-x));
Chart1LineSeries1.AddXY(x, y);
Chart1LineSeries2.AddXY(x, x);
end;
end;
procedure TForm1.Button1Click(Sender:TObject);
begin
Randomize;
LinearLeft.Enabled := RandomRange(0, 2) = 1;
LinearBottom.Enabled := RandomRange(0, 2) = 1;
LogarithmLeft.Enabled := RandomRange(0, 2) = 1;
LogarithmBottom.Enabled := RandomRange(0, 2) = 1;
AutoLeft.Enabled := RandomRange(0, 2) = 1;
AutoBottom.Enabled := RandomRange(0, 2) = 1;
if not LogarithmLeft.Enabled then
CumulLeft.Enabled := RandomRange(0, 2) = 1;
if not LogarithmBottom.Enabled then
CumuBottom.Enabled := RandomRange(0, 2) = 1;
LinearLeft.Scale := (Random(2) * 2 - 1) {plus or minus} * Random * (100 - 0.01) + 0.01;
LinearLeft.Offset := Random * (100 - 0.01) + 0.01;
LinearBottom.Scale := (Random(2) * 2 - 1) {plus or minus} * Random * (100 - 0.01) + 0.01;
LinearBottom.Offset := Random * (100 - 0.01) + 0.01;
Chart1.Invalidate;
Application.ProcessMessages;
HighlightFirstAndLastAxisLabels (chart1.AxisList[0]);
HighlightFirstAndLastAxisLabels (chart1.AxisList[1]);
end;
end.