test

progging - To wander about and beg; to seek food or other supplies by low arts; to seek for advantage by mean shift or tricks.
progging - Programmer slang for writing computer code.

tirsdag 6. september 2011

Position the legend in the upper right corner of a TeeChart chart


The TeeChart has many ways of position the Legend on the chart. You can set it to custom and make it a percentage of the width of the chart, but simply putting it on the right side of the chart and make it stay there when the form was resized, was not straight forward.






The solution was to handle the ChartGetLegendPos and ChartGetLegendRect events.
// The following two event handlers are here to position the legend (and it's text)
// in the upper right corner of the chart. This was not possible to simply configure
// in the TeeChart editor.
procedure TFrm.ChartGetLegendPos(Sender: TCustomChart;
  Index: Integer; var X, Y, XColor: Integer);
var
  diff: Integer;
begin
  diff := X - XColor;
  XColor := Sender.Legend.Left + 7;
  X := XColor + diff;
end;

procedure TFrm.ChartGetLegendRect(Sender: TCustomChart;
  var Rect: TRect);
var
 w, h: Integer;
begin
  w := Rect.Right - Rect.Left;
  h := Rect.Bottom - Rect.Top;
  Rect.Top := Sender.ChartRect.Top;
  Rect.Bottom := Rect.Top + h;
  Rect.Left := Sender.ChartRect.Left + (Sender.ChartWidth - w);
  Rect.Right := Rect.Left + w;
end;

Ingen kommentarer:

Legg inn en kommentar