还是关于dbchart的问题(100分)

  • 主题发起人 主题发起人 老郭
  • 开始时间 开始时间

老郭

Unregistered / Unconfirmed
GUEST, unregistred user!
根据query1的不同选择条件,dbchart的图形作相应的改变,比如 x轴可根据条件为客户名称和收缴人,y轴都为收缴金额总数,
case comboboxex1.ItemIndex of
0: sql:='select b.com_cus_name 客户名称,sum(b.com_area) 合计面积,sum(b.com_ought_mon) 总应收金额,sum(b.com_fact_mon) 总实收金额,sum(a.arr_mon) 总收缴款金额,count(a.arr_nbr) 总收缴次数 from ad_arr a,ad_compact b where b.com_nbr=a.arr_nbr and a.arr_date between '+'TO_DATE('''+FormatDateTime('yyyymmdd', DateTimePicker1.Date )+''',''yyyymmdd'')'+' and '+'TO_DATE('''+FormatDateTime('yyyymmdd', DateTimePicker2.Date )+''',''yyyymmdd'')'+' group by b.com_cus_name';
1: sql:='select arr_man 收缴人,sum(arr_mon) 总收缴金额,count(arr_man) 总收缴次数 from ad_arr where arr_date between '+'TO_DATE('''+FormatDateTime('yyyymmdd', DateTimePicker1.Date )+''',''yyyymmdd'')'+' and '+'TO_DATE('''+FormatDateTime('yyyymmdd', DateTimePicker2.Date )+''',''yyyymmdd'')'+' group by arr_man';
end;
with series1do
begin
DataSource:=query1;
XLabelsSource:=query1.Fields[0].FieldName;
case comboboxex1.ItemIndex of
0: YValues.ValueSource:=query1.Fields[4].FieldName;
1: YValues.ValueSource:=query1.Fields[1].FieldName;
end;
end;
为什么只能第一次选择,能显示出需要的图,而再选择条件时,就提示客户名称字段或收缴人字段找不到。比如第一次选择客户,显示后再选择收缴人时,就提示客户的字段找不到。
好像series的数据源没起作用一样,可我已经设置了!请高手们帮助一下,应该怎么让这个series也同时改变?
 
看看是不是因为下面代码中红色部分所示的 原因?
var
mySeries : TBarSeries;
begin
if comboBox1.ItemIndex = 0 then
begin
DataModule1.adoqStatService.Close;
DataModule1.adoqStatService.SQL.Clear;
DataModule1.adoqStatService.SQL.Add('select count(id) as countnum from service_record where importTime>:importtime1 and importtime<:importtime2 ');
DataModule1.adoqStatService.Parameters.ParamByName('importtime1').Value := DateTimePicker1.DateTime;
DataModule1.adoqStatService.Parameters.ParamByName('importtime2').Value := DateTimePicker2.DateTime;
end else
begin
DataModule1.adoqStatService.Close;
DataModule1.adoqStatService.SQL.Clear;
DataModule1.adoqStatService.SQL.Add('select count(id) as countnum,servicer from service_record where importTime>:importtime1 and importtime<:importtime2 group by Servicer');
DataModule1.adoqStatService.Parameters.ParamByName('importtime1').Value := DateTimePicker1.DateTime;
DataModule1.adoqStatService.Parameters.ParamByName('importtime2').Value := DateTimePicker2.DateTime;
// DataModule1.adoqStatService.Parameters.ParamByName('Servicer').Value := combobox1.text;
end;

[red] if Assigned(mySeries) then
begin
if mySeries.Active= true then
mySeries.Active:=false;
mySeries := nil;
end;
[/red]
mySeries := TBarSeries.Create(Application);
DBChart1.SeriesList.Clear;
mySeries.Title := '服务统计';
mySeries.ParentChart := DBChart1;
DataModule1.adoqStatService.Open;
mySeries.DataSource := DataModule1.adoqStatService;
if comboBox1.ItemIndex = 0 then
mySeries.YValues.ValueSource :='countnum'
else
begin
mySeries.XLabelsSource := DataModule1.adoqStatService.Fields[1].FieldName;
// mySeries.XValues.ValueSource := 'servicer';
mySeries.YValues.ValueSource := 'countnum';
end;
mySeries.Active := true;
 
解决了,还是query的问题把
with query1do
begin
close;
sql.Clear ;
sql.add(search);
open;
end;
query1.Active:=true;
放在DataSource:=query1;的前面就什么问题都解决了
 
To :老郭
我用你的方法怎么会不能用的啊!
我的代码如下:
procedure TForm1.Button1Click(Sender: TObject);
var Str:string;
begin
case comboboxex1.ItemIndex of
0 : str:='select count(company_id) as 总记录数,client_type from Custan_source group by client_type';
1 : str:='select count(company_id) as 总记录数, client_source from Custan_Source group by client_source';
2 : str:='select count(company_id) as 总记录数,client_status from Custan_Source group by client_status';
end;
with series1do
begin
with dmb.Qr_AnCustdo
begin
close;
sql.Clear ;
sql.add(str);
open;
end;
dmb.Qr_AnCust.Active:=true;
DataSource:=dmb.Qr_AnCust;
XLabelsSource:=dmb.Qr_AnCust.Fields[1].FieldName;
case comboboxex1.ItemIndex of
0: XLabelsSource := dmb.Qr_AnCust.Fields[1].FieldName;
1: XLabelsSource := dmb.Qr_AnCust.Fields[1].FieldName;
2: XLabelsSource := dmb.Qr_AnCust.Fields[1].FieldName;
{//0: YValues.ValueSource:=;
//1: YValues.ValueSource:=dmb.Qr_AnCust.Fields[0].FieldName;
2: YValues.ValueSource:=dmb.Qr_AnCust.Fields[0].FieldName;}
end;
YValues.ValueSource:=dmb.Qr_AnCust.Fields[0].FieldName;
end;
end;

按您提供的方法还是不行哦
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
595
import
I
S
回复
0
查看
941
SUNSTONE的Delphi笔记
S
后退
顶部