In one of our charts we have set the legend's CustomPosition property to True. We experienced to following problems:
1. When using TChart's OnGetLegendPos event, the legend entry's customised position applies to the legend entry's text, but not to the legend entry's symbol and checkbox.
2. When using TChart's OnGetLegendRect event to widen the legend's dimensions, the NumCols property of the TChart's Legend is still computed using the TCharts ChartRect rectangle, so a line in the legend is wrapped earlier than expected.
3. When using TChart's OnGetLegendRect event to widen the legend's dimensions, we have to explicitly set the TChart's MarginTop property to avoid overlapping of legend and chart.
TeeChart 8.07 VCL TChart Legend issues
Re: TeeChart 8.07 VCL TChart Legend issues
Hi Collinor,
Could you please confirm that this is what you are noticing?
In the following example I can see both the symbols and the text moved. The symbols seem to respond only to the Y displacement while the text is responding to both X and Y displacement.Collinor wrote:1. When using TChart's OnGetLegendPos event, the legend entry's customised position applies to the legend entry's text, but not to the legend entry's symbol and checkbox.
Code: Select all
uses series;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
Chart1.View3D:=false;
for i:=0 to 3 do
begin
Chart1.AddSeries(TLineSeries.Create(self));
Chart1[i].FillSampleValues;
end;
Chart1.Legend.Alignment:=laTop;
Chart1.Draw;
Chart1.Legend.CustomPosition:=true;
Chart1.MarginTop:=15;
end;
procedure TForm1.Chart1GetLegendPos(Sender: TCustomChart; Index: Integer; var X,
Y, XColor: Integer);
begin
Y:=Y-20;
X:=X-200;
end;
I'm not sure to understand your problem here. Please, take a look at the following example and modify it so we can reproduce the problem or indicate us what would you expect to obtain on it:Collinor wrote:2. When using TChart's OnGetLegendRect event to widen the legend's dimensions, the NumCols property of the TChart's Legend is still computed using the TCharts ChartRect rectangle, so a line in the legend is wrapped earlier than expected.
Code: Select all
uses series;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
Chart1.View3D:=false;
for i:=0 to 10 do
begin
Chart1.AddSeries(TLineSeries.Create(self));
Chart1[i].FillSampleValues;
end;
Chart1.Legend.Alignment:=laTop;
Chart1.Draw;
Chart1.Legend.CustomPosition:=true;
Chart1.MarginTop:=20;
end;
procedure TForm1.Chart1GetLegendRect(Sender: TCustomChart; var Rect: TRect);
begin
Rect.Right:=Rect.Right-80;
Chart1.Title.Text.Text:='NumCols: ' + IntToStr(Chart1.Legend.NumCols);
end;
I think this is an expected behaviour. Once you set the legend CustomPosition to true, the chart fits all the space available and you have to customize the legend position and move the chart according to this custom position (or not if you would like the legend to be inside the chart).Collinor wrote:3. When using TChart's OnGetLegendRect event to widen the legend's dimensions, we have to explicitly set the TChart's MarginTop property to avoid overlapping of legend and chart.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: TeeChart 8.07 VCL TChart Legend issues
Yes, that's what I'am noticing.Yeray wrote:Hi Collinor,
In the following example I can see both the symbols and the text moved. The symbols seem to respond only to the Y displacement while the text is responding to both X and Y displacement.Collinor wrote:1. When using TChart's OnGetLegendPos event, the legend entry's customised position applies to the legend entry's text, but not to the legend entry's symbol and checkbox.Could you please confirm that this is what you are noticing?Code: Select all
uses series; procedure TForm1.FormCreate(Sender: TObject); var i: Integer; begin Chart1.View3D:=false; for i:=0 to 3 do begin Chart1.AddSeries(TLineSeries.Create(self)); Chart1[i].FillSampleValues; end; Chart1.Legend.Alignment:=laTop; Chart1.Draw; Chart1.Legend.CustomPosition:=true; Chart1.MarginTop:=15; end; procedure TForm1.Chart1GetLegendPos(Sender: TCustomChart; Index: Integer; var X, Y, XColor: Integer); begin Y:=Y-20; X:=X-200; end;
Here's my code. The legend must be much wider than the chart to see what's going on. When running my code you will notice, that the items per legend line are computed according to the chart's width, not the legend's width.Yeray wrote:I'm not sure to understand your problem here. Please, take a look at the following example and modify it so we can reproduce the problem or indicate us what would you expect to obtain on it:Collinor wrote:2. When using TChart's OnGetLegendRect event to widen the legend's dimensions, the NumCols property of the TChart's Legend is still computed using the TCharts ChartRect rectangle, so a line in the legend is wrapped earlier than expected.
Code: Select all
uses series;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
Chart1.View3D:=false;
for i:=0 to 10 do
begin
Chart1.AddSeries(TLineSeries.Create(self));
Chart1[i].FillSampleValues;
end;
Chart1.Legend.Alignment:=laTop;
Chart1.Draw;
Chart1.Legend.CustomPosition:=true;
Chart1.Top := 0;
Chart1.Left := 0;
Chart1.MarginTop :=20;
Chart1.MarginLeft := 20;
Chart1.MarginRight := 20;
ClientWidth := Chart1.Width;
ClientHeight := Chart1.Height;
end;
procedure TForm1.Chart1GetLegendRect(Sender: TCustomChart; var Rect: TRect);
begin
Rect.Top := 10;
Rect.Left := 10;
Rect.Right:= Chart1.Width-10;
Chart1.Title.Text.Text:='NumCols: ' + IntToStr(Chart1.Legend.NumCols);
end;
Ok.Yeray wrote:I think this is an expected behaviour. Once you set the legend CustomPosition to true, the chart fits all the space available and you have to customize the legend position and move the chart according to this custom position (or not if you would like the legend to be inside the chart).Collinor wrote:3. When using TChart's OnGetLegendRect event to widen the legend's dimensions, we have to explicitly set the TChart's MarginTop property to avoid overlapping of legend and chart.
Re: TeeChart 8.07 VCL TChart Legend issues
Hi Collinor,
1.
2.
In the meanwhile, I think you could calculate manually the NumCols and overwrite the value so that the legend will show as columns as you've calculated:
1.
Ok, thanks for reporting it. I've added it to the defect list to be fixed in future releases (TV52014883).Collinor wrote:Yes, that's what I'am noticing.
2.
I could reproduce the issue here with your code so I've added it to the wish list to be revised in future releases (TV52014884).Collinor wrote:Here's my code. The legend must be much wider than the chart to see what's going on. When running my code you will notice, that the items per legend line are computed according to the chart's width, not the legend's width.
In the meanwhile, I think you could calculate manually the NumCols and overwrite the value so that the legend will show as columns as you've calculated:
Code: Select all
procedure TForm1.Chart1GetLegendRect(Sender: TCustomChart; var Rect: TRect);
var PixelsInRow: Integer;
begin
Rect.Top := 10;
Rect.Left := 10;
Rect.Right:= Chart1.Width-10;
Chart1.Legend.NumCols:=1;
PixelsInRow:=Chart1.Canvas.TextWidth(Chart1[0].ToString);
while ((Chart1.Legend.NumCols < Chart1.SeriesCount) and ((PixelsInRow + Chart1.Canvas.TextWidth(Chart1[Chart1.Legend.NumCols].ToString) + Chart1.Legend.Symbol.Width - 9) < (Rect.Right - Rect.Left))) do
begin
PixelsInRow:=PixelsInRow + Chart1.Canvas.TextWidth(Chart1[Chart1.Legend.NumCols].ToString) + Chart1.Legend.Symbol.Width - 9;
Chart1.Legend.NumCols:=Chart1.Legend.NumCols+1;
end;
Chart1.Title.Text.Text:='NumCols: ' + IntToStr(Chart1.Legend.NumCols);
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |