您的位置:首页 > 其它

统计图数值动态显示的实现

2011-04-16 20:29 197 查看
PB在做MIS系统时,多种风格的数据窗口为统计查询提供了丰富多彩的显示样式,而统计图风格的数据窗口就是其中最直观有效的,但使用它时有个遗憾,就是不能看到其中准确的数据,只能估计它,本文通过一个实例给出一个实现统计图数值动态显示的方法。
实现过程如下(利用PB9自带数据库,EAS Demo DB V9):
1、建立一个工作空间(workspace),取名为:graphvalue。
2、建立一个应用(application),取名为:graphvalue。
3、准备一个统计图类型选择的图片文件grgallry.bmp,如下图:

4、建立一个Graph风格的数据窗口d_graph_dept,数据窗口的SQL语法为:
SELECT "employee"."emp_id","employee"."sex","department"."dept_name"
FROM "employee" , "department"
WHERE "employee"."dept_id" = "department"."dept_id" ;

5、定义d_graph_dept的属性:
Category:department_dept_name (横坐标为部门)
Value:count(employee_emp_id for graph) (纵坐标为部门人数)
Series:employee_sex (性别)

6、建立Main类型窗口,取名为:w_graph_value,设置如下控件:

控件名 类型 说 明
dw_1 Datawindow 显示统计图,Datawindow object name为:d_graph_dept。
st_help Static Text 用于动态显示数值,BackColor设置为Tooltip。
cb_close Command Button 关闭窗口。

7、编写窗口脚本
1)、定义窗口实例变量
integer ii_aseries = 0
integer ii_datapoint = 0

2)、窗口的open事件:
//数据检索
dw_1.SetTransObject(sqlca)
dw_1.Retrieve()
//隐藏
st_help.Visible = False

3)、数据窗口的ue_mousemove事件(Event ID:pbm_mousemove)脚本:
Integer li_datapoint
Integer li_aseries
String ls_cate_value
Double ldb_value_data
Long ll_length
ldb_value_data = 0
//得到鼠标所在目标的组号和数据号
THIS.ObjectAtPointer("gr_1", li_aseries, li_datapoint)
//得到部门号(即横坐标值)
ls_cate_value = THIS.CategoryName("gr_1", li_datapoint)
// 如果鼠标所在位置没有值显示
IF ls_cate_value = '' OR li_datapoint = 0 OR li_aseries = 0 THEN
st_help.Visible = FALSE //隐藏
li_aseries = 0
ii_datapoint = 0
RETURN
END IF
// 组号和数据号上次一样,则文本保持显示,但位置不再改变
IF li_datapoint = ii_datapoint AND li_aseries = ii_aseries THEN
RETURN
END IF
// 记录组号和数据号,以便下一次比较时用
ii_datapoint = li_datapoint
ii_aseries = li_aseries
//取得纵坐标值
ldb_value_data = THIS.GetData('gr_1', li_aseries , li_datapoint)
//通过st_help显示数值,可根据需要定义
st_help.text = string(ldb_value_data) + "人"
//定位
ll_length = len(st_help.text)
st_help.width = ll_length * 38
st_help.move(Parent.PointerX() - st_help.width/2 ,Parent.PointerY() - st_help.height - 40)
//显示
st_help.Visible = TRUE
4)、cb_close的clicked事件
Close(Parent)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: