How to create multiline legend in teechart?

余生长醉 提交于 2019-12-25 07:30:24

问题


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;



来源:https://stackoverflow.com/questions/23906386/how-to-create-multiline-legend-in-teechart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!