代码如下:
case RadioGroup5.ItemIndex of
0://按年级
sql := 'select nums=count(stinfo.stname),stinfo.stnianji from stinfo inner join zhuanye on stinfo.stzhuanye=zhuanye.zhuanyedm group by stinfo.stnianji';
1://按专业
sql := 'select nums=count(stinfo.stname),zhuanye.zhuanyename from stinfo inner join zhuanye on stinfo.stzhuanye=zhuanye.zhuanyedm group by zhuanye.zhuanyename';
end;
with DataModule1.cdsTongJi do
begin
Close;
Commandtext := sql ;
Open;
end;
mySeries := nil;//前面声明myseries:TChartseries;
case RadioGroup5.ItemIndex of
0:
begin
DBChart1.SeriesList.Clear;
if Assigned(mySeries) then mySeries.Destroy;
mySeries := TBarSeries.Create(self);
mySeries.ParentChart := DBChart1;
mySeries.DataSource := DataModule1.cdsTongji;
mySeries.YValues.ValueSource := 'nums';
mySeries.XLabelsSource := 'stnianji';
mySeries.SeriesColor := clBlue;
end;
1:
begin
DBChart1.SeriesList.Clear;
if Assigned(mySeries) then mySeries := nil;
mySeries := TPieSeries.Create(self);
mySeries.ParentChart := DBChart1;
mySeries.DataSource := DataModule1.cdsTongji;
mySeries.YValues.ValueSource:= 'nums';
mySeries.XLabelsSource := 'zhuanyename';//这里用Xvalues.ValueSource好象不行
end;
end;