我在数据模块中定义了个Query控件,在Form中我使用了个DBChart控件,我没有在chart的属性设置界面里为Seriesline绑定查询结果,我在程序中是这样使用的,但程序运行时曲线没有显示出来,请求高手指教?
附程序:
......
datamodule.DataModule1.QUERY3.Close;
datamodule.DataModule1.QUERY3.SQL.Clear;
datamodule.DataModule1.QUERY3.SQL.Text:='SELECT d001,((t092):fprop1),t093,t094,((t096)*:fprop2) FROM pc10m WHERE D001>:PARAM1 and D001<=:param2 order by d001 desc';
datamodule.DataModule1.QUERY3.ParamBYname('param1').AsDateTime:=dd;
datamodule.DataModule1.QUERY3.ParamBYname('param2').AsDateTime:=t;
datamodule.DataModule1.QUERY3.ParamBYname('fprop1').AsFloat:=fprop1;
datamodule.DataModule1.QUERY3.ParamBYname('fprop2').AsFloat:=fprop2;
datamodule.DataModule1.QUERY3.Open; LineSeries5:=TLineSeries.Create(self);
With LineSeries5 do
begin
ParentChart:=DBChart3;
DataSource:=datamodule.DataModule1.QUERY3;
XLabelsSource:='d001';
YValues.ValueSource:= 'exp_2';
CheckDatasource;
end;
............
附程序:
......
datamodule.DataModule1.QUERY3.Close;
datamodule.DataModule1.QUERY3.SQL.Clear;
datamodule.DataModule1.QUERY3.SQL.Text:='SELECT d001,((t092):fprop1),t093,t094,((t096)*:fprop2) FROM pc10m WHERE D001>:PARAM1 and D001<=:param2 order by d001 desc';
datamodule.DataModule1.QUERY3.ParamBYname('param1').AsDateTime:=dd;
datamodule.DataModule1.QUERY3.ParamBYname('param2').AsDateTime:=t;
datamodule.DataModule1.QUERY3.ParamBYname('fprop1').AsFloat:=fprop1;
datamodule.DataModule1.QUERY3.ParamBYname('fprop2').AsFloat:=fprop2;
datamodule.DataModule1.QUERY3.Open; LineSeries5:=TLineSeries.Create(self);
With LineSeries5 do
begin
ParentChart:=DBChart3;
DataSource:=datamodule.DataModule1.QUERY3;
XLabelsSource:='d001';
YValues.ValueSource:= 'exp_2';
CheckDatasource;
end;
............
2,DBChart有时候很奇怪的,建议还是拉一个到窗体上看看,不要生成,有时要把它删掉再放一个才可以出现数据的图形的,
DBChart1.Series[0].DataSource:=Query1 ;
DBChart1.Series[0].XLabelsSource:='xx';
DBChart1.Series[0].XValues.ValueSource:='yy';
DBChart1.Series[0].YValues.ValueSource:='cc';
DBChart1.Series[0].CheckDataSource;
试试如下方法:
LineSeries5应该在设计时创建
With LineSeries5 do
begin
Clear;//清空
ParentChart:=DBChart3;
//先制空
DataSource:='';
XLabelsSource:='';
YValues.ValueSource:= '';
//在赋值
DataSource:=datamodule.DataModule1.QUERY3;
XLabelsSource:='d001';
YValues.ValueSource:= 'exp_2';
CheckDatasource;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var i:integer;
begin
chart1.Visible:=true;
table1.open;
series1.Clear;
for i:=0 to 9 do
begin
if not table1.Eof then
if i mod 2 =0 then
series1.add(Table1Salary.asinteger,table1lastname.asstring,clyellow)
else series1.add(table1salary.asinteger,table1lastname.asstring,clred)
else begin
table1.first;
abort;
end;
table1.next;
end;