【问题标题】:Draw a pie chart with special properties (alter style and starting point)绘制具有特殊属性的饼图(更改样式和起点)
【发布时间】:2014-02-06 05:20:43
【问题描述】:

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

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

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

我的 Teechart 随 delphi 一起提供。它是 v2011.03.32815。而且也没有类似甜甜圈的图表。所以我认为它需要编码。这可以通过简单地在其画布上放置一个与图表背景匹配的颜色来完成。

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

我画了一个插画家来表达我的意思:

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

【问题讨论】:

标签: delphi delphi-xe2 pie-chart teechart


【解决方案1】:

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

这是我用来生成它的代码。它基本上是一个具有 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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-25
    • 2019-09-13
    • 2016-07-26
    • 1970-01-01
    • 1970-01-01
    • 2012-10-13
    相关资源
    最近更新 更多