今天下午做東西時遇到這樣的問題:
把公司所有員工的業績(回訪數量,收費情況)用一個柱型圖表示出來,要求:
a:y軸表示公司的所有員工且業績為0的員工不顯示出來,x軸表示業績數量(回訪數量+收費情況);
b:按要求對柱圖實現升序或著降序
按以上要求所得思路為:
首先建立一個類(也可以通過結構來實現),類中包含的屬性(或字段)為員工id屬性(或字段),員工回訪數量屬性(或字段),員工收費情況屬性(或字段),員工業績屬性等等。(為了能利用array中的sort需要實現一個接口,會在原碼中說明)
接著通過一個table來通過顏色或著圖片表現出來。下面是實現的原碼:
public class wordload
implements icomparable'一定要實現這個接口,才能利用下面的:array.sort
public pay as integer '維護數量
public go_back as integer '回訪數量
public name as string '用戶名稱
public total_ as integer '維護數量+回訪數量
'以下是想通過那個屬性(或字段),來進行排序
public function compareto(byval obj as object) as integer implements system.icomparable.compareto
dim other as wordload = ctype(obj, wordload)
return total_.compareto(other.total_)
end function
public sub new(byval pay_value as integer, byval go_back_value as integer, byval name_value as string)
pay = pay_value
name = name_value
go_back = go_back_value
total_ = pay + go_back
end sub
end class
public sub creat_test(byval myarr() as wordload, byval mytable as system.web.ui.webcontrols.table)
array.sort(myarr)'說明利用array進行排序
dim rows_num as integer = myarr.length + 1 '說明:人員做為y軸,即人員的個數做為行數,其中為了寫表頭,要加一行,所以表的總行數為,人員個數+1
dim total_comm_num as integer = myarr(myarr.length - 1).total_ '說明:列數為工作量加1,因為人員的名字要占一列
dim pay_width as integer '定義維護寬度
dim go_back_width as integer '定義回訪寬度
dim myimage as htmlcontrols.htmlimage
dim myspan as htmlcontrols.htmlgenericcontrol
dim begin_myrow as new web.ui.webcontrols.tablerow
dim mycell1 as new ui.webcontrols.tablecell
dim mycol1 as new color
mycell1.text = "員工"
mycell1.backcolor = mycol1.green
mycell1.style.add("background-color", "#949294")
mycell1.style.add("font-weight", "bold")
mycell1.style.add("font-size", "18pt")
mycell1.style.add("color", "#ffffff")
mycell1.width = webcontrols.unit.pixel(60)
begin_myrow.cells.add(mycell1)
begin_myrow.width = unit.pixel(700)
for b as integer = 0 to 7 '寫第一行的列
dim mycol as new color
if b = 0 then
dim mycell as new ui.webcontrols.tablecell
'mycell.backcolor = mycol.lightgreen
begin_myrow.cells.add(mycell)
else
myspan = new htmlcontrols.htmlgenericcontrol
myspan.innertext = ((total_comm_num * (b - 1) / 7) / 1).tostring
myspan.style.add("width", "80px") 'width: 100px;
myspan.style.add("height", "40px") ' height: 100px;: bold; font-size: 18pt;color: #ffffff;
myspan.style.add("background-color", "#949294")
myspan.style.add("font-weight", "bold")
myspan.style.add("font-size", "18pt")
myspan.style.add("color", "#ffffff")
begin_myrow.cells(1).controls.add(myspan)
end if
next
mytable.rows.add(begin_myrow)
for i as integer = 0 to rows_num - 2
pay_width = (500 * myarr(i).pay / total_comm_num) / 1 '給維護寬度進行賦值
go_back_width = (500 * myarr(i).go_back / total_comm_num) / 1 '給回訪寬度進行賦值
dim myrow as new web.ui.webcontrols.tablerow
myrow.width = unit.pixel(700)
dim j as integer
'以下循環是添加維護情況
for j = 0 to pay_width
if j = 0 then '在第一列要寫進用戶的名稱
dim mycell as new ui.webcontrols.tablecell
mycell.text = myarr(i).name
mycell.width = webcontrols.unit.pixel(60)
dim mycol as new color
mycell.bordercolor = mycol.deeppink
myrow.cells.add(mycell)
dim mycell2 as new ui.webcontrols.tablecell
myrow.cells.add(mycell2)
else '在第二列添加圖片信息
myspan = new htmlcontrols.htmlgenericcontrol
myimage = new htmlcontrols.htmlimage
myimage.src = "images/navbar.gif" '要顯示的中間圖片
myspan.controls.add(myimage)
myrow.cells(1).controls.add(myspan)
end if
next
'以下循環是添加回訪情況
for j = 0 to go_back_width
myspan = new htmlcontrols.htmlgenericcontrol
myimage = new htmlcontrols.htmlimage
myimage.src = "images/navbar2.gif" '要顯示的中間圖片
myspan.controls.add(myimage)
myrow.cells(1).controls.add(myspan)
next
mytable.rows.add(myrow)
next
mytable.width = unit.pixel(700)
end sub
后記:以上代碼在win2000+vs.net 中運行通過,由于是剛剛測試完成,代碼有點亂(變量名稱也是隨意的,有點不能代表意思!)
新聞熱點
疑難解答
圖片精選