注册 登录
编程论坛 PowerBuilder

如何在PB中实现图形(饼图,直方图,点图等)

liucuimaomao 发布于 2007-05-21 09:46, 4459 次点击

 本人在学习中要在PB中实现以上各图的显示,数据在数据库里,要从数据库里查询到这些数据生成这些图形并对这些图形进行分析,从而得出加工误差的情况,望高手指点下.谢谢!本人用的是PB9.0版本.

11 回复
#2
liucuimaomao2007-05-21 10:17

我等了半天了怎么没人指点下呢

#3
liucuimaomao2007-05-21 10:34

int w,jj,bhgp[],a[],ww,www,aa,tt,c,i
string b
w=1
for jj=1 to dw_4.rowcount() //找到原因代号

bhgp[w]=dw_4.getitemnumber(jj,"bad_part_number") //得到不合格品数量 bhgp[w]=52,65,45,89,20,15

a[w]=jj //a[w]=1,2,3,4,5,6
w=w+1 //w=7
next
c=w - 1

for ww=1 to c - 1 //www是不合格品数量最多的数
if bhgp[ww]>bhgp[ww+1] then
tt=bhgp[ww+1]
bhgp[ww+1]=bhgp[ww]
bhgp[ww]=tt //bhgp[ww+1]=max
end if
next
www=bhgp[c]
for i=1 to dw_4.rowcount() //找到原因代号
if www=dw_4.getitemnumber(i,"bad_part_number") then
aa=dw_4.getitemnumber(i,"reason_id")
end if
next
for i=1 to dw_2.rowcount() //找到原因代号
if aa=dw_2.getitemnumber(i,"reason_id") then
b=dw_2.getitemstring(aa,"reason")
end if
next


messagebox("提示",&
"最大不合格品数量为"+string(www)+",它所对应的原因是"+string(b)+",这就是最主要的影响因素")



参考别人做的是以上程序但窗口上根本没DW_1和DW_2控件。不知道从何而来,我用的是窗口.DW_1的形式但出错,出错原因是null object reference at line 4 in clicked event of object cb_1 of w_hege(我的窗口名),真诚的希望高手指点下

#4
路過2007-05-21 11:28
1、PB中实现图形(饼图,直方图,点图等):
file-->new-->datawindow-->graph 可以建立各種圖形。
2、DW_1和DW_2不是控件,是datawindow;也要把別人的DW_1和DW_2拷過來。
3、w_hege窗口的cb_1 對象的clicked事件中第四行,空的對象。
希望對你有幫助。
#5
liucuimaomao2007-05-23 09:03
回复:(liucuimaomao)如何在PB中实现图形(饼图,...
我试了下,但里面的Catagory和value 值应该如何设置呢?
#6
路過2007-05-23 15:02
Catagory :橫坐標的值
value :指縱坐標的值。
選擇表的欄位分別設定。
#7
liucuimaomao2007-05-24 21:48
回复:(liucuimaomao)如何在PB中实现图形(饼图,...

谢谢

#8
路過2007-05-25 16:25

你好,上班qq不太方便。以下是我做的graph:
table:test
name char
number number
month char
no char

name number month no
a產品 50 02 4
b產品 100 02 5
c產品 45 02 6
a產品 20 01 1
b產品 30 01 2
c產品 50 01 3
a產品 82 03 7
b產品 41 03 8
c產品 12 03 9



方法1:graph控件
用graph控件要增加一個dw窗口或建個動態窗口,將數據放在此窗口中,通過按鈕把數據數據顯示在graph中。

按鈕clicked事件代碼:
int rows,i,yis
string xis,ls_mon
integer SeriesNbr1,SeriesNbr2,SeriesNbr3
dw_1.SetTransObject(sqlca)
dw_1.Retrieve()
rows = rowcount(dw_1)
messagebox('rows',rows)
if rows>0 then
gr_1.SetRedraw(False) //
gr_1.reset(all!) //清空graph的所有數據 
//gr_1.addseries('number') //
//gr_1.addseries('01')
//SeriesNbr1 = gr_1.FindSeries("01")
//
//gr_1.InsertSeries("02", SeriesNbr1)
//SeriesNbr2 = gr_1.FindSeries("02")
//
//gr_1.InsertSeries("03", SeriesNbr2)
//SeriesNbr3 = gr_1.FindSeries("03")


gr_1.addseries('a產品~')// 增加一組
SeriesNbr1 = gr_1.FindSeries('a產品~')//在圖形中獲得一個組的數據。

gr_1.InsertSeries('b產品~', SeriesNbr1)//插入一組
SeriesNbr2 = gr_1.FindSeries('b產品~')

gr_1.InsertSeries('c產品~', SeriesNbr2)//插入一組
SeriesNbr3 = gr_1.FindSeries('c產品~')


for i =1 to rows

if SeriesNbr1 = 1 then
xis=getitemstring(dw_1,i,'month')
yis=getitemnumber(dw_1,i,'number')
ls_mon=getitemstring(dw_1,i,'name')

if isnull(yis) then
yis=0
end if
end if


//if SeriesNbr1 = integer(ls_mon) then
//
//gr_1.adddata(SeriesNbr1,yis,xis)
//
//elseif SeriesNbr2 = integer(ls_mon) then
//
//gr_1.adddata(SeriesNbr2,yis,xis)
//
//elseif SeriesNbr3 = integer(ls_mon) then
//
//gr_1.adddata(SeriesNbr3,yis,xis)
//
//end if


if ls_mon = 'a產品~' then

gr_1.adddata(SeriesNbr1,yis,xis)

elseif ls_mon = 'b產品~' then

gr_1.adddata(SeriesNbr2,yis,xis)

elseif ls_mon = 'c產品~' then

gr_1.adddata(SeriesNbr3,yis,xis)

end if

next
gr_1.SetRedraw(True) //相當於刷新吧

end if

方法2:new datawindow--->graph
按鈕clicked事件代碼:
dw_1.SetTransObject(sqlca)
dw_1.Retrieve()
dw_1.accepttext()
點擊按鈕可顯示圖。
如有問題,我再把pbl發給你。

#9
liucuimaomao2007-05-28 09:03
回复:(liucuimaomao)如何在PB中实现图形(饼图,...

   我用了第二种方法,但运行不出来

#10
liucuimaomao2007-05-28 09:05
回复:(liucuimaomao)如何在PB中实现图形(饼图,...
直方图点图有案例么?
#11
liucuimaomao2007-05-28 09:09
dw_1.accepttext()
是不是dw_1.accept后跟的是建的表名?
#12
路過2007-05-28 10:12

dw_1.accepttext()不是跟的是建的表名,
Syntax
dwcontrol.AcceptText ( )
英文不太好,不會翻譯。自我理解,接收文件的意思。
Applies the contents of the DataWindow's edit control to the current item in the buffer of a DataWindow control or DataStore. The data in the edit control must pass the validation rule for the column before it can be stored in the item.

我把pbl 發給你。我的mail是sbtxgtgmy@163.com ,不要拒收喔

1