TeeChart 8.07 VCL TChart Legend issues

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Collinor
Newbie
Newbie
Posts: 15
Joined: Wed Oct 31, 2007 12:00 am

TeeChart 8.07 VCL TChart Legend issues

Post by Collinor » Mon May 10, 2010 6:59 am

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.

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: TeeChart 8.07 VCL TChart Legend issues

Post by Yeray » Tue May 11, 2010 11:41 am

Hi Collinor,
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.
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.

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;
Could you please confirm that this is what you are noticing?
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.
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:

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;
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.
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).
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Collinor
Newbie
Newbie
Posts: 15
Joined: Wed Oct 31, 2007 12:00 am

Re: TeeChart 8.07 VCL TChart Legend issues

Post by Collinor » Fri May 14, 2010 1:08 pm

Yeray wrote:Hi Collinor,
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.
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.

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;
Could you please confirm that this is what you are noticing?
Yes, that's what I'am noticing.
Yeray wrote:
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.
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:
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.

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;
Yeray wrote:
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.
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).
Ok.

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: TeeChart 8.07 VCL TChart Legend issues

Post by Yeray » Fri May 14, 2010 2:14 pm

Hi Collinor,

1.
Collinor wrote:Yes, that's what I'am noticing.
Ok, thanks for reporting it. I've added it to the defect list to be fixed in future releases (TV52014883).

2.
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.
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).
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,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply