有关于DBCHART刷新的问题。
procedure TFMBZBT.RadioButton1Click(Sender: TObject);var bars:TpieSeries; sqlstr:string;begin DBChart1.Series[0].DataSource:=nil; //清空数据源 bars:=Tpieseries.Create(dbchart1); dbchart1.AddSeries(bars); dbchart1.Series[0].ColorEachPoint:=True; //数据块不同色 try case Tcomponent(sender).Tag of 0: begin sqlstr:='select yblb,count(*) from INPATIENT_INFO group by yblb'; bars.PieValues.ValueSource:='count(*)'; bars.XLabelsSource:='yblb'; end; 1: begin sqlstr:='select doc_result,count(*) from INPATIENT_INFO group by doc_result'; bars.PieValues.ValueSource:='count(*)'; bars.XLabelsSource:='doc_result'; end; end; adobt.Close; adobt.SQL.Clear; adobt.SQL.add(sqlstr); adobt.Open; dbchart1.AutoRefresh:=false; dbchart1.AutoRefresh:=true; dbchart1.Series[0].Active:=false; DBChart1.Series[0].DataSource:=adobt; dbchart1.Series[0].Active:=true; except showmessage('没有数据可以过滤'); end;end;这个语句实现的是,如下图:点选这两个选项,可以出现对应的饼图。问题:一开始点一个没问题,可以出现对应的饼图。可是再点第二个就出现了如下图的错误提示:
procedure TFMBZBT.RadioButton1Click(Sender: TObject);var bars:TpieSeries; sqlstr:string;begin DBChart1.Series[0].DataSource:=nil; //清空数据源 bars:=Tpieseries.Create(dbchart1); dbchart1.AddSeries(bars); dbchart1.Series[0].ColorEachPoint:=True; //数据块不同色 try case Tcomponent(sender).Tag of 0: begin sqlstr:='select yblb,count(*) from INPATIENT_INFO group by yblb'; bars.PieValues.ValueSource:='count(*)'; bars.XLabelsSource:='yblb'; end; 1: begin sqlstr:='select doc_result,count(*) from INPATIENT_INFO group by doc_result'; bars.PieValues.ValueSource:='count(*)'; bars.XLabelsSource:='doc_result'; end; end; adobt.Close; adobt.SQL.Clear; adobt.SQL.add(sqlstr); adobt.Open; dbchart1.AutoRefresh:=false; dbchart1.AutoRefresh:=true; dbchart1.Series[0].Active:=false; DBChart1.Series[0].DataSource:=adobt; dbchart1.Series[0].Active:=true; except showmessage('没有数据可以过滤'); end;end;
bars.XLabelsSource:='doc_result'; end; end; adobt.Close; adobt.SQL.Clear; adobt.SQL.add(sqlstr); adobt.Open; dbchart1.AutoRefresh:=false; dbchart1.AutoRefresh:=true; dbchart1.Series[0].Active:=false; DBChart1.Series[0].DataSource:=adobt; dbchart1.Series[0].Active:=true; except showmessage('没有数据可以过滤'); end;end;