我最近刚好做了一个动态显示的程序现共享出来:
unit TB;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ToolWin, ComCtrls, ExtCtrls, TeeProcs, TeEngine, Chart, DBChart,
Series, Buttons, ColorGrd,Db;
type
TForm_TB = class(TForm)
DBChart1: TDBChart;
Bevel1: TBevel;
Bevel2: TBevel;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
Bevel3: TBevel;
Label1: TLabel;
ComboBox2: TComboBox;
Bevel4: TBevel;
Label2: TLabel;
ComboBox3: TComboBox;
Bevel5: TBevel;
ComboBox1: TComboBox;
Label3: TLabel;
Bevel6: TBevel;
ScrollBar1: TScrollBar;
Label4: TLabel;
Edit1: TEdit;
ColorDialog1: TColorDialog;
Series1: TPieSeries;
Series2: TFastLineSeries;
Series3: TBarSeries;
BitBtn1: TBitBtn;
Bevel7: TBevel;
BitBtn2: TBitBtn;
procedure ScrollBar1Scroll(Sender: TObject;
ScrollCode: TScrollCode;
var ScrollPos: Integer);
procedure BitBtn2Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
procedure RadioButton1Click(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure ComboBox3Change(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BeforeShow(Dts:TdataSet;Tit,LTit,BTit:string;X,Y:string);
private
S:integer;
{ Private declarations }
public
{ Public declarations }
end;
var
Form_TB: TForm_TB;
implementation
uses Main;
{$R *.DFM}
procedure TForm_TB.BeforeShow(Dts:TdataSet;Tit,LTit,BTit:string;X,Y:string);
begin
S:=0;
RadioButton1.Checked:=true;
Combobox2.ItemIndex:=0;
Combobox3.ItemIndex:=0;
Combobox1.ItemIndex:=0;
DBChart1.Title.Text[0]:=Tit;
DBChart1.LeftAxis.Title.Caption:=LTit;
DBChart1.BottomAxis.Title.Caption:=BTit;
DBChart1.Series[0].DataSource:=Dts;
DBChart1.Series[0].XLabelsSource:=Y;
DBChart1.Series[0].YValues.ValueSource:=X;
DBChart1.Series[0].Marks.Style:=smsLabel;
DBChart1.Series[0].Active:=true;
DBChart1.Series[1].Active:=false;
DBChart1.Series[2].Active:=false;
DBChart1.View3D:=true;
DBChart1.View3DOptions.Orthogonal:=false;
end;
procedure TForm_TB.ScrollBar1Scroll(Sender: TObject;
ScrollCode: TScrollCode;
var ScrollPos: Integer);
begin
if DBChart1.View3D=false then
begin
Edit1.Text:=inttostr(ScrollBar1.position);
DBChart1.ZoomPercent(strtoint(Edit1.Text));
end
else
begin
Edit1.Text:=inttostr(ScrollBar1.position);
DBChart1.View3DOptions.ZoomText:=true;
DBChart1.View3DOptions.zoom:=strtoint(Edit1.Text);
end;
end;
procedure TForm_TB.BitBtn2Click(Sender: TObject);
begin
Close;
end;
procedure TForm_TB.RadioButton1Click(Sender: TObject);
begin
DBChart1.View3D:=True;
end;
procedure TForm_TB.RadioButton2Click(Sender: TObject);
begin
DBChart1.View3D:=false;
end;
procedure TForm_TB.ComboBox2Change(Sender: TObject);
begin
DBChart1.Series[0].Active:=false;
DBChart1.Series[1].Active:=false;
DBChart1.Series[2].Active:=false;
S:=combobox2.ItemIndex;
if s>1 then
s:=2;
DBChart1.Series.DataSource:=DBChart1.Series[0].DataSource;
DBChart1.Series.YValues.ValueSource:=DBChart1.Series[0].YValues.ValueSource;
DBChart1.Series.XLabelsSource:=DBChart1.Series[0].XLabelsSource;
DBChart1.Series.checkdatasource;
DBChart1.Series.Active:=true;
DBChart1.Series.Marks.Style:=smsLabel;
DBChart1.AutoRefresh:=true;
case combobox2.ItemIndex of
2:
begin
( DBChart1.Series[2] as TBarSeries ).BarStyle:=bsRectangle;
end;
3:
begin
( DBChart1.Series[2] as TBarSeries ).BarStyle:=bsPyramid;
end;
4:
begin
( DBChart1.Series[2] as TBarSeries ).BarStyle:=bsInvPyramid;
end;
5:
begin
( DBChart1.Series[2] as TBarSeries ).BarStyle:=bsCilinder;
end;
6:
begin
( DBChart1.Series[2] as TBarSeries ).BarStyle:=bsEllipse;
end;
7:
begin
( DBChart1.Series[2] as TBarSeries ).BarStyle:=bsRectGradient;
end;
8:
begin
( DBChart1.Series[2] as TBarSeries ).BarStyle:=bsCone;
end;
end;
if combobox2.ItemIndex=0 then
DBChart1.View3DOptions.Orthogonal:=false
else
DBChart1.View3DOptions.Orthogonal:=true;
end;
procedure TForm_TB.ComboBox1Change(Sender: TObject);
var
t:integer;
begin
case ComboBox1.ItemIndex of
0:
begin
for t := 0 to DBChart1.Series.Count - 1do
DBChart1.Series.ValueColor[ t ] :=clRed;
DBChart1.Series.ColorEachPoint:=false;
end;
1:
begin
if ColorDialog1.Execute then
begin
for t := 0 to DBChart1.Series.Count - 1do
DBChart1.Series.ValueColor[ t ]:=ColorDialog1.Color;
end;
end;
2:
begin
DBChart1.Series.ColorEachPoint:=true;
DBChart1.Refresh;
end;
end;
end;
procedure TForm_TB.ComboBox3Change(Sender: TObject);
var
t:integer;
begin
case ComboBox3.ItemIndex of
0:
begin
DBChart1.BackWall.Color:=clOlive;
end;
1:
begin
if ColorDialog1.Execute then
begin
DBChart1.BackWall.Color:=ColorDialog1.Color;
end;
end;
end;
end;
procedure TForm_TB.BitBtn1Click(Sender: TObject);
begin
DBChart1.Print;
end;
end.
------调用的主程序------
unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, DBGrids, Db, DBTables, ComCtrls, ToolWin, StdCtrls;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
Table1: TTable;
DBGrid1: TDBGrid;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ComboBox1: TComboBox;
procedure ToolButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses TB;
{$R *.DFM}
procedure TForm1.ToolButton1Click(Sender: TObject);
begin
Form_TB:=TForm_TB.Create(Application);
Form_TB.BeforeShow(Table1,'图表标题','左标题','底标题','Salary','FirstName');
Form_TB.show;
end;
end.