帮我看看这段代码有什么问题,为什么series只能显示2条以上数据,如果Q_Chart只有一条记录的话就显示不出来
unit cgStat;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, XPComboBox, DB, ADODB, ExtCtrls, TeeProcs, TeEngine,
Chart, Buttons, XPButton, Series;type
TForm1 = class(TForm)
Chart1: TChart;
Q_Chart: TADOQuery;
Comb_Depart: TXPComboBox;
Comb_Year: TXPComboBox;
Btn_Stat: TXPButton;
Comb_Style: TXPComboBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Series1: TFastLineSeries;
Series2: TFastLineSeries;
Series3: TFastLineSeries;
Series4: TFastLineSeries;
Series5: TFastLineSeries;
Series6: TFastLineSeries;
Series7: TFastLineSeries;
Series8: TFastLineSeries;
Series9: TFastLineSeries;
Series10: TFastLineSeries;
procedure FormCreate(Sender: TObject);
procedure Btn_StatClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var j:integer;
begin
chart1.LeftAxis.Maximum:=100;
chart1.BottomAxis.Maximum:=12;
chart1.BottomAxis.Minimum:=1;
for j:=0 to chart1.SeriesCount -1 do
begin
chart1.Series[j].Active:=false;
end;
{===========================================================将部门输入Comb_Depart=============================================================}
with Q_Chart do
begin
if active then
close;
sql.Clear;
sql.Add('select distinct depart from s_stock');
open;
end; while not Q_chart.Eof do
begin
Comb_Depart.Items.Add(Q_chart.fieldbyname('depart').Value );
Q_Chart.Next;
end;
Comb_Depart.ItemIndex:=0;
{============================================================将日期的年份输入Comb_Year============================================================}
with Q_Chart do
begin
if active then
close;
sql.Clear;
sql.Add('select distinct Year(mon) as mon from s_stock ');
sql.Add(' order by mon DESC');
open;
end;
while not Q_Chart.Eof do
begin
Comb_Year.Items.Add(Q_Chart.fieldbyname('mon').Value );
Q_Chart.Next;
end;
Comb_Year.ItemIndex:=0;
end;procedure TForm1.Btn_StatClick(Sender: TObject);
var i:integer;
begin
for i:=0 to Chart1.SeriesCount -1 do
begin
Chart1.Series[i].Clear;
if Chart1.Series[i].Active =true then
Chart1.Series[i].Active:=false;
end; Chart1.Title.Text.Clear;
Chart1.Title.Text.Add(Comb_Depart.Text +Comb_Year.Text +'年采购统计图'); with Q_Chart do
begin
if active then
close;
sql.Clear;
sql.Add('select distinct bgyp from s_stock where');
sql.Add(' depart ='''+Comb_Depart.text+''' and');
sql.Add(' year(mon) ='+quotedstr(Comb_Year.text));
open;
end; for i:=0 to Q_Chart.RecordCount -1 do
begin
Chart1.Series[i].Active:=true;
end; i:=0;
while (not Q_Chart.Eof) do
begin
Chart1.Series[i].Title:=Q_Chart.fieldbyname('bgyp').AsString;;
i:=i+1;
Q_Chart.next;
end;end;end.
明天要验收了,那位大虾帮下忙啊
unit cgStat;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, XPComboBox, DB, ADODB, ExtCtrls, TeeProcs, TeEngine,
Chart, Buttons, XPButton, Series;type
TForm1 = class(TForm)
Chart1: TChart;
Q_Chart: TADOQuery;
Comb_Depart: TXPComboBox;
Comb_Year: TXPComboBox;
Btn_Stat: TXPButton;
Comb_Style: TXPComboBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Series1: TFastLineSeries;
Series2: TFastLineSeries;
Series3: TFastLineSeries;
Series4: TFastLineSeries;
Series5: TFastLineSeries;
Series6: TFastLineSeries;
Series7: TFastLineSeries;
Series8: TFastLineSeries;
Series9: TFastLineSeries;
Series10: TFastLineSeries;
procedure FormCreate(Sender: TObject);
procedure Btn_StatClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var j:integer;
begin
chart1.LeftAxis.Maximum:=100;
chart1.BottomAxis.Maximum:=12;
chart1.BottomAxis.Minimum:=1;
for j:=0 to chart1.SeriesCount -1 do
begin
chart1.Series[j].Active:=false;
end;
{===========================================================将部门输入Comb_Depart=============================================================}
with Q_Chart do
begin
if active then
close;
sql.Clear;
sql.Add('select distinct depart from s_stock');
open;
end; while not Q_chart.Eof do
begin
Comb_Depart.Items.Add(Q_chart.fieldbyname('depart').Value );
Q_Chart.Next;
end;
Comb_Depart.ItemIndex:=0;
{============================================================将日期的年份输入Comb_Year============================================================}
with Q_Chart do
begin
if active then
close;
sql.Clear;
sql.Add('select distinct Year(mon) as mon from s_stock ');
sql.Add(' order by mon DESC');
open;
end;
while not Q_Chart.Eof do
begin
Comb_Year.Items.Add(Q_Chart.fieldbyname('mon').Value );
Q_Chart.Next;
end;
Comb_Year.ItemIndex:=0;
end;procedure TForm1.Btn_StatClick(Sender: TObject);
var i:integer;
begin
for i:=0 to Chart1.SeriesCount -1 do
begin
Chart1.Series[i].Clear;
if Chart1.Series[i].Active =true then
Chart1.Series[i].Active:=false;
end; Chart1.Title.Text.Clear;
Chart1.Title.Text.Add(Comb_Depart.Text +Comb_Year.Text +'年采购统计图'); with Q_Chart do
begin
if active then
close;
sql.Clear;
sql.Add('select distinct bgyp from s_stock where');
sql.Add(' depart ='''+Comb_Depart.text+''' and');
sql.Add(' year(mon) ='+quotedstr(Comb_Year.text));
open;
end; for i:=0 to Q_Chart.RecordCount -1 do
begin
Chart1.Series[i].Active:=true;
end; i:=0;
while (not Q_Chart.Eof) do
begin
Chart1.Series[i].Title:=Q_Chart.fieldbyname('bgyp').AsString;;
i:=i+1;
Q_Chart.next;
end;end;end.
明天要验收了,那位大虾帮下忙啊
解决方案 »
- ▲平时咬不开的核桃,这会轻轻一用力就开,莫非凌晨时身体机能最强?
- 难!检测进程是否死锁。UP有分。
- 求delphi设计说明书模板
- 安装报表fastreport时的问题?
- 在sql语句中引入变量????
- kylix, delphi,多线程下载!!
- F1Book控件在KeyPree事件中,我发现在向控件中输入数据时,KeyPress事件只能响应一次!
- 高手问题,请问DELPHI和SQLSERVER的接口
- 类似QQ或360的皮肤控件
- 为什么执行时提示文件系统错,无法复制,错误代码1026?高手请进!
- 谁能介绍一下Table的Filter的写法(主要是+和'的用法)
- 如何得到SQL执行后的Recordcount的条数并把这个数加入到另一个数据库?
while (not Q_Chart.Eof) do
begin
Chart1.Series[i].Title:=Q_Chart.fieldbyname('bgyp').AsString;;
i:=i+1;
Q_Chart.next;
end;
你在i:=0前加一句Q_Chart.first试试我试了,一条记录也可以出来啊。
供參考,我這裡測試也通過procedure TPRO_EFFPLATO_F.LoadBuindFamilyName;
var
i:Integer;
begin
cx_order.Properties.Items.Clear;
adoq_loadmodel.Active:=True;
adoq_loadmodel.First;
for i:=0 to adoq_loadmodel.RecordCount -1 do
begin
cx_order.Properties.Items.Add(adoq_loadmodel.FieldValues['Model']);
adoq_loadmodel.Next;
end;
end;
procedure TPRO_EFFPLATO_F.FormShow(Sender: TObject);
var
Chart:TChart;
S:TChartSeries;
TmpFile:string;
begin
inherited;
Chart1.Title.Text.Text:='工時管理趨勢坐標平面圖';
Chart1.Title.Font.Size:=12;
Chart1.Title.Font.Color:=clBlue;
Chart1.Gradient.Visible:=True;
Chart1.Gradient.StartColor:=clGreen;
Chart1.Gradient.EndColor:=clYellow;
end;