绘制具有特殊属性的饼图(更改样式和起点)

时间:2014-02-06 05:20:44

标签: delphi delphi-xe2 pie-chart teechart

我想创建一个具有此功能的饼图:

  • 它的起点变为90度(如量表组件)
  • 顺时针转动。
  • 显示值的固定标记。
  • 甜甜圈风格。

我检查饼图属性。但我没有找到任何相应的功能。

我有Teechart与delphi一起发货。这是v2011.03.32815。并且没有像图表那样的甜甜圈。所以我认为需要编码。它可以通过简单地在其画布上放置一个圆圈,其颜色与图表背景相匹配。

我可以使用仪表组件。但它没有反别名功能(Teechart有TeeGDIPlus)。

我画了一个插图画家的意思:
enter image description here

Q1:如何绘制/编码图表?

1 个答案:

答案 0 :(得分:4)

这里有一个简单的例子,向您展示如何使用TeeChart绘制类似于图片中的TDonutSeries。这是它的样子: donut

这是我用来生成它的代码。它基本上是一个具有2个值和宽笔的TDonutSeries。和文本的两个TAnnotationTools:

uses TeCanvas, TeeDonut, TeeTools, Series;

procedure TForm1.FormCreate(Sender: TObject);
var donut1: TDonutSeries;
    annot1, annot2: TAnnotationTool;
    tmpX, tmpY: Integer;
begin
  (Chart1.Canvas as TGDIPlusCanvas).AntiAliasText:=gpfBest;
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;

  with Chart1.Foot do
  begin
    Text.Text:='G1';
    Font.Color:=clBlack;
    Font.Style:=[];
    Font.Size:=25;
  end;

  donut1:=Chart1.AddSeries(TDonutSeries) as TDonutSeries;
  annot1:=Chart1.Tools.Add(TAnnotationTool) as TAnnotationTool;
  annot2:=Chart1.Tools.Add(TAnnotationTool) as TAnnotationTool;

  with donut1 do
  begin
    Add(33, '', clWhite);
    Add(66, '', RGB(0, 178, 247));
    Pen.Color:=RGB(0, 178, 247);
    Pen.Width:=8;
    RotationAngle:=90;
    Marks.Visible:=false;
    CustomXRadius:=120;
    CustomYRadius:=120;
  end;

  with annot1 do
  begin
    Text:='56%';
    Shape.Transparent:=true;
    Shape.Font.Size:=25;
  end;

  with annot2 do
  begin
    Text:='33%';
    Shape.Transparent:=true;
    Shape.Font.Size:=15;
  end;

  Chart1.Draw;

  with annot1 do
  begin
    Shape.Left:=donut1.CircleXCenter-(Shape.Width div 2);
    Shape.Top:=donut1.CircleYCenter-(Shape.Height div 2);
  end;

  with annot2 do
  begin
    donut1.AngleToPos(180, donut1.CustomXRadius, donut1.CustomYRadius, tmpX, tmpY);
    Shape.Left:=tmpX-(Shape.Width div 2)+30;
    Shape.Top:=tmpY-(Shape.Height div 2)+30;
  end;
end;

如果您更喜欢使用系列标记而不是TAnnotationTools,可以尝试按如下方式设置:

  donut1.Marks.Transparent:=True;
  donut1.Marks.Font.Size:=20;
  donut1.Marks.Callout.ArrowHead:=ahSolid;