Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...