PB9.0控件之Graph

    pb在数据交互方面有着得天独厚的优势。对于数据的显示和处理简单、直观、易于理解。PowerBuilder会用到GRAPH作为一种输出工具,直观地显示用户想要看到的数据及数据间的关系。易于对数据进行分析,可以到达Excel图标的功能,但是简单的多。下面就这次毕业论文中使用的实际例子,看看Graph的使用方法和优势。

    这里,实现了不同输入条件产生不同的报表。在界面中放置一个Graph控件,界面如下:   

PB9.0控件之Graph_第1张图片

    在窗体加载时,给出所有成绩的成绩分布情况。这么做其实意义不大。之后可以根据选择的条件动态的改变图表的数据源。

生成图表按钮的代码如下:  

intmsg       //标记条件控件是否输入
int msg2
msg=0
msg2=0
string condition[2]
//第一组,条件
if trim(tab_result.tabpage_pie.ddlb_fieldname1.text)<>"请选择" then
msg=msg +1
end if
if trim(tab_result.tabpage_pie.ddlb_operator3.text)<>"请选择" then
msg=msg+ 1
end if
iftrim(tab_result.tabpage_pie.sle_value4.text)<>"" then
   msg=msg + 1
end if
//第二组,条件
if trim(tab_result.tabpage_pie.ddlb_fieldname2.text)<>"请选择" then
msg=msg +1
end if
if trim(tab_result.tabpage_pie.ddlb_operator4.text)<>"请选择" then
msg=msg+ 1
end if
iftrim(tab_result.tabpage_pie.sle_value5.text)<>"" then
   msg=msg + 1
end if
 
if msg = 3 then        //表明第一组条件输入合法
 
condition[1]= " and "+tab_result.tabpage_pie.dw_condition.describe(tab_result.tabpage_pie.ddlb_fieldname1.text+ "_t.text") + " " +tab_result.tabpage_pie.dw_condition.describe(tab_result.tabpage_pie.ddlb_operator3.text+ "_t.text") + " '"+trim(tab_result.tabpage_pie.sle_value4.text) + "'"
 
end if
 
if msg2=3 then     //表明第二组条件输入合法
 
condition[2]= " and "+tab_result.tabpage_pie.dw_condition.describe(tab_result.tabpage_pie.ddlb_fieldname2.text+ "_t.text") + " " +tab_result.tabpage_pie.dw_condition.describe(tab_result.tabpage_pie.ddlb_operator4.text+ "_t.text") + " '"+trim(tab_result.tabpage_pie.sle_value5.text) + "'"
 
end if
integerthecount[5],seriesno
integer i
string thesql[5],kh
seriesno=tab_result.tabpage_pie.gr_pie.addseries("成绩分布")          //添加数据系列
 
if isNUll(condition[1])=false and isNUll(condition[2])=falsethen         //得到动态的
    thesql[1]="select count(*) fromv_result where result>='90'" +condition[1] +condition[2]
    thesql[2]="select count(*) fromv_result where result>='80' and result<'90'"+condition[1]+condition[2]
    thesql[3]="select count(*) fromv_result where result>='70' and result<'80'"+condition[1]+condition[2]
    thesql[4]="select count(*) fromv_result where result>='60'and result<'70'"+condition[1]+condition[2]
    thesql[5]="select count(*) fromv_result where result<'60'" +condition[1]+condition[2]
elseifisNUll(condition[1])=false then
 thesql[1]="select count(*) from v_resultwhere result>='90'" +condition[1]
    thesql[2]="select count(*) fromv_result where result>='80' and result<'90'" +condition[1]
    thesql[3]="select count(*) fromv_result where result>='70' and result<'80'" +condition[1]
    thesql[4]="select count(*) fromv_result where result>='60'and result<'70'" +condition[1]
    thesql[5]="select count(*) fromv_result where result<'60'" +condition[1]
elseifisnull(condition[2])=false then
 thesql[1]="select count(*) from v_resultwhere result>='90'" +condition[2]
    thesql[2]="select count(*) fromv_result where result>='80' and result<'90'" +condition[2]
    thesql[3]="select count(*) fromv_result where result>='70' and result<'80'" +condition[2]
    thesql[4]="select count(*) fromv_result where result>='60'and result<'70'" +condition[2]
    thesql[5]="select count(*) fromv_result where result<'60'" +condition[2]
else
thesql[1]="selectcount(*) from v_result where result>='90'"
    thesql[2]="select count(*) fromv_result where result>='80' and result<'90'"
    thesql[3]="select count(*) fromv_result where result>='70' and result<'80'"
    thesql[4]="select count(*) fromv_result where result>='60'and result<'70'"
    thesql[5]="select count(*) fromv_result where result<'60'"
end if
for i = 1 to 5
DECLARE mycursor DYNAMIC CURSOR FORSQLSA;                //查询数据,使用游标读取
PREPARESQLSA From :thesql[i];
openmycursor;
 
ifsqlca.sqlcode<0 then
messagebox("数据库出错","游标无法打开")
return
endif
FETCHmycursor INTO :thecount[i];
closemycursor;
next
tab_result.tabpage_pie.gr_pie.addcategory("90分以上")       //添加类别
tab_result.tabpage_pie.gr_pie.addcategory("80-90分")
tab_result.tabpage_pie.gr_pie.addcategory("70-80分")
tab_result.tabpage_pie.gr_pie.addcategory("60-70分")
tab_result.tabpage_pie.gr_pie.addcategory("不及格")
 
tab_result.tabpage_pie.gr_pie.adddata(seriesno,thecount[1],"90分以上")        //为不同的类别加载数据
tab_result.tabpage_pie.gr_pie.adddata(seriesno,thecount[2],"80-90分")
tab_result.tabpage_pie.gr_pie.adddata(seriesno,thecount[3],"70-80分")
tab_result.tabpage_pie.gr_pie.adddata(seriesno,thecount[4],"60-70分")
tab_result.tabpage_pie.gr_pie.adddata(seriesno,thecount[5],"不及格")
 
tab_result.tabpage_pie.gr_pie.title= sle_value4.text +sle_value5.text +"成绩分布图"          //更改图表名称
 

    这次毕业设计用PB9.0来实现,给我最大的感受是:PB9.0是我目前遇到的对数据的交互最好的语言,简单直观易用。但是在其他方面不是那么的人性化。总体的说就是,有点很明显,缺点也很明显。

你可能感兴趣的:(PB9.0控件之Graph)