In the data comparison or presentation, an image of the chart is not only very intuitive, but also very vivid. This example introduces how to design the image of three-dimensional pie chart in Delphi.
Add a Tvtchart component and a TTimer component to the form where the Tvtchart component is used to display the pie chart, and the TTimer component is used to constantly change the data of the pie chart to achieve dynamic effects. The design-finished main interface is shown in Figure 1.
Figure 1 Main interface
The program first joins the math unit in the uses segment, and then adds the Randomize () statement during the initialization of the form, which causes the random number to be restarted each time the program is run, lest the same random number as the previous run.
In order to generate a dynamic pie chart, add the following code to the response process of the TTimer component: Procedure Tform1.timer1timer (Sender:tobject);
begin
self.VtChart1.Row:=0;
self.VtChart1.Column:=0;
self.VtChart1.Data:=FloatToStr(Random(200));
end;
The TTimer component Interval property is set to 1000, that is, every 1000 milliseconds, the program changes the data in the 1th row, column 1th of the pie.
The program code is as follows:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, VCFI, ExtCtrls, math;
type
TForm1 = class(TForm)
VtChart1: TVtChart;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
self.VtChart1.Row:=0;
self.VtChart1.Column:=0;
self.VtChart1.Data:=FloatToStr(Random(200));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize();
end;
end.
Save the file, and then press the F9 key to run the program. The pie chart changes as the program runs, as shown in Figure 2.
Figure 2 Pie chart in change
The Tvtchart component not only can display pie charts, but also can display many kinds of three-dimensional and two-dimensional graphics, if you can make full use of it, it will add a lot to their program.