Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
507 views
in Technique[技术] by (71.8m points)

How to create multiline legend in teechart?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

legend manually drawn


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...