How to create multiline legend in teechart?

2019-09-01 15:27发布

问题:

Does anybody know if there a way to write multiline legend of a chart? I've tried to add TeeLineSeparator or #13, and it doesn't work?

Thanks very much

回答1:

I'm afraid not in the current legend. The alternatives are to use the CustomLegend tool TeeChart Pro provides or to directly draw your shapes and strings in the OnAfterDraw event using custom drawing techniques. Ie:

uses Series, TeCanvas;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Chart1.Legend.Visible:=false;
  Chart1.MarginRight:=22;

  for i:=0 to 4 do
    with Chart1.AddSeries(TBarSeries) as TBarSeries do
    begin
      Title:='Long title in Series number ' + IntToStr(i);
      FillSampleValues;
      Marks.Visible:=false;
      MultiBar:=mbStacked;
    end;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var tmpHeight, i: Integer;
begin
  tmpHeight:=Chart1.SeriesCount*33;

  with Chart1.Canvas do
  begin
    Rectangle(Chart1.Width-130, 50, Chart1.Width-10, 50+tmpHeight);

    for i:=0 to Chart1.SeriesCount-1 do
    begin
      Brush.Color:=Chart1[i].Color;
      Rectangle(Chart1.Width-120, 65+i*30, Chart1.Width-120+15, 65+i*30+15);

      TextOut(Chart1.Width-100, 60+i*30, WrapText(Chart1[i].Title, #13#10, ['.',' ',#9,'-'], 15));
    end;
  end;
end;