Search code examples
delphiteechart

Is it possible to draw TeeChart PieSeries titles on the pies instead of the legend?


I have a DBChart with four PieSeries on it. Each chart has multiple slices, and is multicolored. I'd like to have the title of each series written either on it or beneath it, instead of the legend. Is there any easy way to accomplish this? I'm using TeeChart Standard v2011.03.32815 VCL


Solution

  • The Pro version includes the Annotation tool that would be useful here.

    With the Standard version, you could just have 4 TDBCharts as mentioned in a comment above, or you could also draw manually your texts on the canvas. Ie:

    procedure TForm1.FormCreate(Sender: TObject);
    var i: Integer;
    begin
      for i:=0 to 3 do
        with Chart1.AddSeries(TPieSeries) as TPieSeries do
        begin
          FillSampleValues;
        end;
    end;
    
    procedure TForm1.Chart1AfterDraw(Sender: TObject);
    var i, tmpX, tmpY: Integer;
        tmpStr1, tmpStr2: string;
    begin
      tmpStr1:='My Pie nº';
    
      for i:=0 to Chart1.SeriesCount-1 do
      begin
        tmpStr2:=tmpStr1+IntToStr(i+1);
        with (Chart1[i] as TPieSeries), Chart1.Canvas do
        begin
          tmpX:=CircleXCenter-(TextWidth(tmpStr2) div 2);
          if (i<2) then
            tmpY:=CircleRect.Top-20
          else
            tmpY:=CircleRect.Bottom+10;
    
          TextOut(tmpX, tmpY, tmpStr2);
        end;
      end;
    end;