- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以,我遇到的问题是我在图表上为每个学生显示两个条形,我只想要其中一个。不过它们的高度是正确的,所以这很好。这是我的Delphi源代码;
strlstField := TStringList.Create();
ADOQGetResults.SQL.clear;
ADOQGetResults.SQL.Add(
'SELECT Results.StudentID, SUM(Results.Rawmark) as TRM, StudentInfo.Fname '+
'FROM (StudentInfo INNER JOIN Results ON StudentInfo.StudentID = Results.StudentID) '+
'WHERE (((StudentInfo.StudentID)=Results.StudentID)) AND Results.TestID =12 '+
'GROUP BY StudentInfo.Fname, Results.StudentID'
);
ADOQGetResults.Active := True;
ADOQGetResults.Open;
DBChart1.Title.Text.Clear;
DBChart1.Title.Text.Add('Class leaderboard');
DBChart1.Title.Font.Size := 15;
DBChart1.LeftAxis.Title.Font.Size := 12;
DBChart1.LeftAxis.Title.Caption := 'Total marks';
DBChart1.BottomAxis.Title.Font.Size := 12;
DBChart1.BottomAxis.Title.Caption := 'Student';
//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 ADOQGetResults.FieldCount - 1 do
begin
strlstField.Add(ADOQGetResults.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 := ADOQGetResults;
Series[intCnt].XLabelsSource := 'Fname';
Series[intCnt].YValues.ValueSource := 'TRM';
end;
end;
我一整天都在努力找出问题所在,所以如果有人能提供帮助,我将非常感激!这是图表现在的样子; http://oi48.tinypic.com/6qelba.jpg
最佳答案
为什么要循环结果中的每个字段(在查询中返回 3 个字段)并在结果中添加一系列每个字段?这几乎就像您认为字段数等于行数之类的。其次,我大胆猜测您的查询中的某些内容加上您的数据(我们看不到)可能会导致您在查询结果中获得比您预期更多的行。
当您的查询始终返回 3 个字段、1 个字段未绘制图表、1 个字段是系列标签源、1 个字段是系列值源时,为什么要销毁并重新添加系列?只需在设计时在 dfm 中静态创建一个系列,然后忘记所有这些疯狂的运行时内容。您是否尝试过双击 dbchart 并在其中添加一个 BarChart 系列?
这有效并且代码少得多。顺便说一句,您不需要打开数据集两次。注意,我这里使用的是Delphi自带的DBDEMOS.mdb数据库,方便大家一起玩。添加一个 db 图表,并在 DESIGNTIME 向其中添加一个条形图系列。根据需要进行配置。使用此代码。下面的数据集是 TADODataset。
-
dataset.CommandText := 'select EmpNo,FirstName,Salary from employee';
dataset.Active := True;
DBChart1.Title.Text.Clear;
DBChart1.Title.Text.Add('Class leaderboard');
DBChart1.Title.Font.Size := 15;
DBChart1.LeftAxis.Title.Font.Size := 12;
DBChart1.LeftAxis.Title.Caption := 'Total marks';
DBChart1.BottomAxis.Title.Font.Size := 12;
DBChart1.BottomAxis.Title.Caption := 'Student';
if DBChart1.SeriesCount<1 then
begin
raise Exception.Create('Add series to your chart in the dfm ONCE.');
end;
//To set source for Series
with DBChart1 do begin
Series[0].Title := 'Test';
Series[0].DataSource := dataset;
Series[0].XLabelsSource := 'FirstName';
Series[0].YValues.ValueSource := 'Salary';
end;
请注意,这仍然比您绝对需要编写的代码要多。您可以在 dfm(表单设计器)中完成大部分工作(如果不是全部的话)。
关于delphi - 简单的 Delphi DBcharting,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15592253/
所以,我遇到的问题是我在图表上为每个学生显示两个条形,我只想要其中一个。不过它们的高度是正确的,所以这很好。这是我的Delphi源代码; strlstField := TStringList.Crea
我是一名优秀的程序员,十分优秀!