今天下午做东西时遇到这样的问题:
把公司所有员工的业绩(回访数量,收费情况)用一个柱型图表示出来,要求:
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 中运行通过,由于是刚刚测试完成,代码有点乱(变量名称也是随意的,有点不能代表意思!)
新闻热点
疑难解答
图片精选