哪位大侠知道动态创建图表(DBCHART)

ywzwyw 2003-12-19 03:40:21
哪位大侠知道动态创建图表(DBCHART)

字段由用户选择?
...全文
6 点赞 收藏 6
写回复
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiangwangz 2004-01-15
好方法 !
回复
hotdog911 2004-01-15
收藏了,谢谢
回复
eliphe 2003-12-22
看楼上的
回复
FlyBird2004 2003-12-22
给你一篇例子吧!(对比图,全都是动态生成的)
var
qstForm: TqstForm;
MyChart:Array of TLineSeries;
MyQuery:Array of TQuery;

implementation

{$R *.DFM}

procedure TqstForm.FormCreate(Sender: TObject);
var
node,nodes:ttreenode;
num,i,Sum:Integer;
begin
DateTimePicker1.Width:=105;
DateTimePicker2.Width:=105;
DateTimePicker1.DateTime:=Now()-1;
datetimepicker2.datetime:=now();
if not Table1.Active then
Table1.Active:=true;
if not Table2.Active then
Table2.Active:=true;
if Not table3.Active then
table3.open;
node:=nil;
nodes:=nil;
node:=TreeView1.Items.Add(node,Table3.fieldbyname('centername').asstring);
node.ImageIndex:=0;
node.SelectedIndex:=0;
nodes:=node;
while not Table1.Eof do
begin
node:=TreeView1.Items.AddChild(node,Table1.fieldbyname('centername').asstring);
node.ImageIndex:=1;
node.SelectedIndex:=1;
Table1.Next;
node:=nodes;
end;
while not Table2.Eof do
begin
num:=Table2.fieldbyname('centerno').asinteger;
for i:=0 to TreeView1.Items.Count-1 do
begin
node:=TreeView1.Items[i];
if Table1.Locate('centername',TreeView1.Items[i].Text,[]) then
begin
if strtoint(trim(Table1.FieldByName('centerno').asstring))=num then
begin
node:=TreeView1.Items.Addchild(node,Table2.fieldbyname('SurveyPointname').asstring);
node.ImageIndex:=2;
node.SelectedIndex:=2;
end;
end;
end;
Table2.Next;
end;

Sum:=Table2.RecordCount;
SetLength(MyChart,Sum+3);
SetLength(MyQuery,Sum+3);
Table2.First; I:=3;
while Not Table2.Eof do
begin
MyChart[I]:=TLineSeries.Create(Self);
MyChart[I].ParentChart:=DBChart3;
MyQuery[I]:=TQuery.Create(Self);
MyQuery[I].DatabaseName:=Database1.DatabaseName;
Inc(I); Table2.Next;
end;

Shape1.Brush.Color:=Series1.SeriesColor;
Shape2.Brush.Color:=DBChart1.LeftWall.Color;
Shape2.Brush.Color:=DBChart1.BottomWall.Color;
end;

procedure TqstForm.TreeView1Change(Sender: TObject; Node: TTreeNode);
var
Str,Id,FName:string;
I:integer;
begin
Str:=''; Id:=''; FName:='';
case node.Level of
1:begin
Table2.First; I:=3;
while Not Table2.Eof do
begin
Id:=Table2.fieldbyname('surveypointno').AsString;
FName:=Table2.FieldValues['surveypointname'];
MyQuery[I].SQL.Clear;
Str:='select surveytime 时间,middlevalue1 水位,finalvalue1 流量'+
' from a11czzk1 where surveypointno='+''''+id+''''+
' and surveytime>='+''''+datetostr(DateTimePicker1.Time)+''''+
' and surveytime<='+''''+datetostr(DateTimePicker2.Time+1)+'''';
MyQuery[I].SQL.Add(Str);
MyQuery[I].Open;

MyChart[I].DataSource:=MyQuery[I];
MyChart[I].XLabelsSource:='时间';
MyChart[I].XValues.ValueSource:='时间';
MyChart[I].YValues.ValueSource:='水位';
MyChart[I].CheckDataSource;
MyChart[I].LinePen.Width:=3;
MyChart[I].Title:=FName;
MyChart[I].Active:=true;
MyChart[I].RefreshSeries;
Inc(I); Table2.Next;
Str:=''; Id:=''; FName:='';
end;
end;
回复
ywzwyw 2003-12-19
例子我知道,但是没有动态增加曲线的实例
回复
hnhb 2003-12-19
我是用的TeeChart来显示图表的,D6带了完整的示例
回复
发动态
发帖子
网络通信/分布式开发
创建于2007-08-02

1566

社区成员

Delphi 网络通信/分布式开发
申请成为版主
社区公告
暂无公告