我使用以下代码来创建动态系列的 TDBChart。我使用了 MS-Access 和 TADOQuery 组件。按钮单击事件上的代码。
var
qryData: TADOQuery;
intCnt: integer;
strlstField: TStringList;
begin
strlstField := TStringList.Create();
qryData := TADOQuery.Create(nil);
qryData.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0; Data Source=' + ExtractFilePath(Application.ExeName) + 'data.mdb';
qryData.SQL.Add('SELECT dept_name,2005 as [2005],2006 as [2006],2007 as [2007],'+
'2008 as [2008],2009 as [2009],2010 as [2010], 2011 as [2211] FROM SALES');
qryData.Active := True;
DBChart1.Title.Text.Clear;
DBChart1.Title.Text.Add('Department Wise Sales Report');
DBChart1.Title.Font.Size := 14;
DBChart1.LeftAxis.Title.Font.Size := 12;
DBChart1.LeftAxis.Title.Caption := 'Sales in Rs.';
DBChart1.BottomAxis.Title.Font.Size := 12;
DBChart1.BottomAxis.Title.Caption := 'Department Name';
//Charting Series
//To Remove Old Series
for intCnt := DBChart1.SeriesCount -1 downto 0 do
DBChart1.Series[intCnt].Free;
//To Add New Series
for intCnt := 1 to qryData.FieldCount - 1 do begin
strlstField.Add(qryData.FieldList[intCnt].FieldName);
DBChart1.AddSeries(TBarSeries.Create(nil));
end;
//To set source for Series
for intCnt:= 0 to DBChart1.SeriesCount -1 do begin
with DBChart1 do begin
Series[intCnt].Clear;
Series[intCnt].Title := strlstField[intCnt];
Series[intCnt].ParentChart := DBChart1;
Series[intCnt].DataSource := qryData;
Series[intCnt].XLabelsSource := 'dept_name';
Series[intCnt].YValues.ValueSource := strlstField[intCnt];
end;
end;
问题:当我更改数据库中的数据并重新运行时,应用程序图表保持不变。在图表系列中没有进行反射。上面的代码有什么错误吗?
另一个问题是,在图片中,系列的值是 2000,但我在数据库中添加了所有高于 20,000 的值。