日期:2008-10-18 浏览次数:20433 次
今天下午做东西时遇到这样的问题:
把公司所有员工的业绩(回访数量,收费情况)用一个柱型图表示出来,要求:
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.A