Sizing charts in ChartLayout
Posted: Thu Nov 23, 2023 2:43 pm
Hi,
I have difficulties sizing charts using tChartLayout. I have five charts in one row. The first chart should have a left axis, while the other four should just have a line with no labels or ticks. That is easily achieved by setting only the left axis on the leftmost chart to visible.
I managed to get the charts to be the same size, by setting .... LeftAxis.Resizecharts to false for the leftmost chart but then the axis on the leftmost chart does not show the labels (only the ticks). If I, in my naivety, add a marginleft to the leftmost chart then I am back to square one: Visible axis labels , but more narrow chart.I hope there is a solution for this.
Below is the code (The form is just blank)
Best
Jon
I have difficulties sizing charts using tChartLayout. I have five charts in one row. The first chart should have a left axis, while the other four should just have a line with no labels or ticks. That is easily achieved by setting only the left axis on the leftmost chart to visible.
I managed to get the charts to be the same size, by setting .... LeftAxis.Resizecharts to false for the leftmost chart but then the axis on the leftmost chart does not show the labels (only the ticks). If I, in my naivety, add a marginleft to the leftmost chart then I am back to square one: Visible axis labels , but more narrow chart.I hope there is a solution for this.
Below is the code (The form is just blank)
Best
Jon
Code: Select all
unit Gtest;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, VCLTee.TeeChartLayout, Vcl.StdCtrls,
VCLTee.TeePNG, VCLTee.TeExport, VclTee.TeeGDIPlus,
VCLTee.TeEngine, Vcl.ExtCtrls, VCLTee.TeeProcs, VCLTee.Chart, VCLTee.Series,
VCLTee.TeeEdit, VCLTee.TeePreviewPanel;
type
TForm3 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Procedure AddCharts;
end;
var
Form3: TForm3;
ChLay: TChartLayout;
implementation
{$R *.dfm}
Procedure FormatChart(ch: Tchart);
Begin
Ch.Border.Visible:=False;
Ch.MarginLeft:=3;
Ch.MarginRight:=3;
Ch.View3D:=False;
Ch.Legend.Visible:=False;
Ch.BottomAxis.Grid.Visible:=False;
Ch.LeftAxis.Grid.Style:=psClear; //psDot;
Ch.LeftAxis.Grid.SmallDots:=True;
Ch.LeftAxis.Grid.Visible:=False;
Ch.Walls.Visible:=False;
Ch.Walls.Right.Visible:=False;
Ch.Walls.Left.Visible:=True;
End;
procedure TForm3.AddCharts;
var ChartCounter : Integer;
tmp,tmp2 : TChartSeries;
begin
ChLay:=TchartLayout.Create(self);
ChLay.Parent:=self;
ChLay.Top:=20;
ChLay.Left:=20;
ChLay.Columns:=5;
ChLay.Width:=Form3.Width- ChLay.Left*2;
ChLay.Height:=Form3.Height-40;
ChLay.HorzScrollBar.Visible:=False;
ChLay.ChartWidth:=ChLay.Width div ChLay.Columns -20 ;
for ChartCounter:=0 to 4 do begin
// Create two series
tmp:=TLineSeries.Create(Self);
tmp.FillSampleValues;
tmp2:=TLineSeries.Create(Self);
tmp2.FillSampleValues;
// Set a different color for each series
tmp.Color:=GetDefaultColor(ChartCounter);
tmp2.Color:=GetDefaultColor(ChartCounter+10);
// Add series to layout
ChLay.Add('Chart '+IntToStr(ChartCounter)).AddSeries(tmp);
ChLay.charts[ChartCounter].chart.addseries(tmp2);
FormatChart(ChLay.Charts[ChartCounter].Chart);
// Special case for leftmost chart
if ChartCounter mod 5 <> 0 then Begin
ChLay.Charts[ChartCounter].Chart.LeftAxis.Labels:=False;
End else Begin
ChLay.Charts[ChartCounter].Chart.LeftAxis.ResizeChart:=False ;
//ChLay.charts[ChartCounter].Chart.MarginLeft:=20;
End;
end; // for
end; // addcharts
procedure TForm3.FormCreate(Sender: TObject);
begin
AddCharts;
end;
end.