图形datawindow 如何在鼠标移在图形上时显示对应的数量

lovesmileman 2010-01-06 06:01:02
图形datawindow 如何在鼠标移在图形上时显示对应的数量
...全文
98 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dawugui 2010-01-07
  • 打赏
  • 举报
回复
[Quote=引用楼主 lovesmileman 的回复:]
图形datawindow 如何在鼠标移在图形上时显示对应的数量

[/Quote]
你是指柱状图吗?


统计图数值动态显示的实现
(独孤求败二零零四年一月十九日整理于深圳市南山区)
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)

8、运行效果图:

BenyMo 2010-01-06
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 pb8 的回复:]
一般的办法是在数据窗口里面加一个text,再新增数据窗口的mousemove事件,在事件里面加下面的代码,
当移到指定结点的时候就会显示相应的值了~~
grObjectType ClickedObject
string ls_series,ls_value
string ls_tips
int li_series, li_category

ClickedObject = this.ObjectAtPointer (is_graph, li_series, li_category)
if ii_category = li_category then return
ii_category = li_category
ls_tips = ''
ls_series = this.SeriesName ( is_graph, li_series)
Choose Case ClickedObject
Case TypeGraph!
//ls_tips = 'TypeGraph'
Case TypeTitle!
//ls_tips = 'TypeTitle'
Case TypeData!

ls_value = string(this.GetData(is_graph, li_series, li_category))
if isnumber(ls_value) then
ls_value = String(dec(ls_value),'##,###,###.00')
end if
ls_tips = this.CategoryName(is_graph,li_category) + '    ' + ls_series +'    (' + ls_value + ')'
Case TypeCategory!
//ls_tips = 'TypeCategory'
Case TypeCategoryAxis!
//ls_tips = 'TypeCategoryAxis'
Case TypeCategoryLabel!
//ls_tips = 'TypeCategoryLabel'
Case TypeSeriesAxis!
//ls_tips = 'TypeSeriesAxis'
Case TypeSeriesLabel!
//ls_tips = 'TypeSeriesLabel'
Case TypeValueAxis!
//ls_tips = 'TypeValueAxis'
Case TypeValueLabel!
//ls_tips = 'TypeValueLabel'
Case Else
ls_tips = ''
End Choose

if isnull(ls_tips) then ls_tips=''

再按你的方式显示ls_tips就好了
[/Quote]
果然是一个好办法
pb8 2010-01-06
  • 打赏
  • 举报
回复
一般的办法是在数据窗口里面加一个text,再新增数据窗口的mousemove事件,在事件里面加下面的代码,
当移到指定结点的时候就会显示相应的值了~~
grObjectType ClickedObject
string ls_series,ls_value
string ls_tips
int li_series, li_category

ClickedObject = this.ObjectAtPointer (is_graph, li_series, li_category)
if ii_category = li_category then return
ii_category = li_category
ls_tips = ''
ls_series = this.SeriesName ( is_graph, li_series)
Choose Case ClickedObject
Case TypeGraph!
//ls_tips = 'TypeGraph'
Case TypeTitle!
//ls_tips = 'TypeTitle'
Case TypeData!

ls_value = string(this.GetData(is_graph, li_series, li_category))
if isnumber(ls_value) then
ls_value = String(dec(ls_value),'##,###,###.00')
end if
ls_tips = this.CategoryName(is_graph,li_category) + ' ' + ls_series +' (' + ls_value + ')'
Case TypeCategory!
//ls_tips = 'TypeCategory'
Case TypeCategoryAxis!
//ls_tips = 'TypeCategoryAxis'
Case TypeCategoryLabel!
//ls_tips = 'TypeCategoryLabel'
Case TypeSeriesAxis!
//ls_tips = 'TypeSeriesAxis'
Case TypeSeriesLabel!
//ls_tips = 'TypeSeriesLabel'
Case TypeValueAxis!
//ls_tips = 'TypeValueAxis'
Case TypeValueLabel!
//ls_tips = 'TypeValueLabel'
Case Else
ls_tips = ''
End Choose

if isnull(ls_tips) then ls_tips=''

再按你的方式显示ls_tips就好了

611

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder DataWindow
社区管理员
  • DataWindow社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧