您的位置:首页 > 其它

ComponentOne WebChart的一个应用实例

2007-02-09 17:05 295 查看
前台页面:

<table border="0" cellspacing="0" cellpadding="0" class="table_list">
<tr>
<td>
 </td>
</tr>
<tr>
<!-- 关键部分开始 -->
<td>
<!--查询开始-->
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="dscx">
<tr>
<td>
 选择统计项: 
<asp:DropDownList ID="ddlSelectQueryField" runat="server">
<asp:ListItem>-在列表中选择-</asp:ListItem>
<asp:ListItem Value="STAFF_DEPT_ID">所属部门</asp:ListItem>
<asp:ListItem Value="STAFF_DUTY_ID">职务岗位</asp:ListItem>
<asp:ListItem Value="STAFF_SEX">性别</asp:ListItem>
<asp:ListItem Value="STAFF_NATION">所属民族</asp:ListItem>
<asp:ListItem Value="STAFF_SCHOOL_RECORD">学历</asp:ListItem>
<asp:ListItem Value="STAFF_MARRY">婚姻状况</asp:ListItem>
<asp:ListItem Value="STAFF_SPECIAL">所学专业</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
 显示统计结果: 
<asp:ImageButton ID="ImageView" runat="server" ToolTip="图形" OnClick="ImageView_Click" />
       
<asp:ImageButton ID="InfoView" runat="server" ToolTip="明细" OnClick="InfoView_Click" />
</td>
</tr>
</table>
<!--查询结束-->
<!--列表数据外框开始-->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<!--列表数据开始-->
<asp:GridView ID="gvList" runat="server" BorderStyle="None" CssClass="data_tab" CellSpacing="1"
CellPadding="2" BorderWidth="0px" AllowSorting="True" OnRowDataBound="gvList_RowDataBound"
AutoGenerateColumns="False" OnSelectedIndexChanged="gvList_SelectedIndexChanged"
OnRowDeleting="gvList_RowDeleting" OnRowEditing="gvList_RowEditing" OnSorting="gvList_Sorting">
<HeaderStyle CssClass="data_th" />
<RowStyle BackColor="#F1F1F1" Wrap="False" Height="28px" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="ROWNUM" HeaderText="序号" AccessibleHeaderText="ROWNUM">
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField>
<ItemStyle Wrap="False" CssClass="hiddencol" />
<HeaderStyle Wrap="False" CssClass="hiddencol" />
<ControlStyle CssClass="hiddencol" />
<FooterStyle CssClass="hiddencol" />
</asp:BoundField>
<asp:BoundField HeaderText="项目内容" DataField="pro_name" >
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField HeaderText="项目人数" DataField="pro_num" >
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:TemplateField HeaderText="动作" ShowHeader="False" Visible="False">
<ItemTemplate>
<table>
<tr>
<td class="dsgv">
<asp:ImageButton ID="ImageButton2" runat="server" ToolTip="查看" ImageUrl="~/_include/images/btn_view.gif"
CommandName="Select" />
</td>
<td class="dsgv">
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/_include/images/btn_xg.gif"
CommandName="Edit" ToolTip="修改" />
</td>
<td class="dsgv">
<asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="~/_include/images/btn_sc.gif"
CommandName="Delete" ToolTip="删除" OnClientClick="return confirm('确认要删除吗?');" />
</td>
</tr>
</table>
</ItemTemplate>
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:TemplateField>
</Columns>
</asp:GridView>
<!--列表数据结束-->
</td>
</tr>
<tr>
<td align="center">
<C1WebChart:C1WebChart ID="C1WebChart1" runat="server">
</C1WebChart:C1WebChart>
</td>
</tr>
</table>
<!--列表数据外框结束-->
<center>
<asp:HyperLink ID="HyperLink1" runat="server" ImageUrl="~/_include/images/btn_fh.gif"
NavigateUrl="javascript:history.back()"></asp:HyperLink>
</center>
</td>
<!-- 关键部分结束 -->
</tr>
</table>

后台代码:

#region 页面事件处理程序

#region 页面事件处理程序 -- Page事件
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
C1WebChart1.Visible = false;
ViewState["CurrentPage"] = 1;
//ListGridViewDataBind();
}
}
#endregion

#region 页面事件处理程序 --- gridView事件
/// <summary>
/// 数据列绑定时
/// </summary>
protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "ItemOver(this)";
}
}

#endregion

#region 页面事件处理程序 -- 其他事件

/******************需要在具体页面中修改的地方**************************************/
//-----添加其他事件------------
//..
//..
//-----处理脚本------------

//查看图形
protected void ImageView_Click(object sender, ImageClickEventArgs e)
{
if (ddlSelectQueryField.Text == "-在列表中选择-")
{
WebUtils.MsgBox(this,"请选择项目");
}
else
{
C1WebChart1.Visible = true;
ListGridViewDataBind();
}
}
//查看明细
protected void InfoView_Click(object sender, ImageClickEventArgs e)
{
if (ddlSelectQueryField.Text != "-在列表中选择-")
{
string[] pro_son_list = new string[] { };//定义需要显示项目LIST(不重复)
int[] pro_son_numlist = new int[] { };//定义需要显示项目的相应的个数list
int allnum = 0;
getList(ref pro_son_list, ref pro_son_numlist, ref allnum);

DataTable dt = new DataTable();
DataColumn newDataColumn;

newDataColumn = dt.Columns.Add("ROWNUM", Type.GetType("System.Int32"));
newDataColumn.AutoIncrement = true;
newDataColumn.AutoIncrementSeed = 1;
newDataColumn.AutoIncrementStep = 1;
newDataColumn.AllowDBNull = false;
newDataColumn.Unique = true;

newDataColumn = dt.Columns.Add("pro_name", Type.GetType("System.String"));
newDataColumn.AllowDBNull = false;

newDataColumn = dt.Columns.Add("pro_num", Type.GetType("System.String"));
newDataColumn.AllowDBNull = false;

DataRow newDr;

for (int i = 0; i < pro_son_list.Length; i++)
{
float y = pro_son_numlist[i] * 100 / allnum;
newDr = dt.NewRow();
newDr["pro_name"] = pro_son_list[i];
newDr["pro_num"] = y.ToString() + "%";
dt.Rows.Add(newDr);
}
gvList.DataSource = dt.DefaultView;
gvList.DataBind();
}
else
{
WebUtils.MsgBox(this, "请选择项目");
}
}

#endregion

#endregion

#region 页面自定义方法
/// <summary>
/// 从数据库获取数据,并重置翻页条
/// </summary>
protected void ListGridViewDataBind()
{

C1WebChart1.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
C1WebChart1.ImageRenderMethod = ImageRenderMethodEnum.HttpHandler;
C1WebChart1.ChartGroups.Group0.ChartType = Chart2DTypeEnum.Pie; //图表

// 类型,Chart2DTypeEnum枚举下有所有的图表样式,如饼图/柱状图

C1WebChart1.Width = 800; //图表区域宽度
C1WebChart1.Height = 400;
this.GetPieData();

}

//X轴标签(坐标)的方法,直接调用即可
public void AddAxisX()
{
// label x axis with product names
Axis ax = C1WebChart1.ChartArea.AxisX;
ax.ValueLabels.Clear();
ax.AnnoMethod = AnnotationMethodEnum.ValueLabels;
for(int i = 0; i < 100; i++)
{
//DataRowView drv = dv[i];
ax.ValueLabels.Add(i, (i+1).ToString());
}
try
{
ax.Max = 10 - .5;
}
catch {}
}

//Y轴标签(坐标)的方法,直接调用即可

public void AddAxisY()
{
// label y axis with product names
Axis ay = C1WebChart1.ChartArea.AxisY;
ay.ValueLabels.Clear();
ay.AnnoMethod = AnnotationMethodEnum.ValueLabels;
for(int i = 0; i < 10; i++)
{
//DataRowView drv = dv[i];
ay.ValueLabels.Add(i, (50*i).ToString());
}
try
{
ay.Max = 20 - .5;
}
catch {}
}

public void GetPieData()
{

string[] pro_son_list = new string[] { };//定义需要显示项目LIST(不重复)
int[] pro_son_numlist = new int[] { };//定义需要显示项目的相应的个数list
int allnum=0;
getList(ref pro_son_list,ref pro_son_numlist,ref allnum);

C1WebChart1.Legend.Visible = true;
this.AddAxisX();
//this.AddAxisY();

//PointF[] data = new PointF[10];
PointF[] data = new PointF[pro_son_list.Length];
for (int i = 0; i < data.Length; i++)
{
float y = pro_son_numlist[i]*100 / allnum;
//float y = float.Parse((3 * i + 5).ToString());
//y = float.Parse(y.ToString());
data[i] = new PointF(i, y);
}

ChartDataSeriesCollection dscoll = C1WebChart1.ChartGroups[0].ChartData.SeriesList;
dscoll.Clear();

C1WebChart1.ChartLabels.LabelsCollection.Clear();//清空标签对象

for (int i = 0; i < data.Length; i++)
{
//ChartDataSeries series = C1WebChart1.ChartGroups[0].ChartData.SeriesList[i];
//series.PointData.CopyDataIn(data);// 这里的data是PointF类型
ChartDataSeries series = dscoll.AddNewSeries();
series.PointData.Length = 1;
series.Y[0] = data[i].Y;
series.Label = pro_son_list[i];

//加标签
C1.Win.C1Chart.Label lbl = C1WebChart1.ChartLabels.LabelsCollection.AddNewLabel();
lbl.Text = string.Format("{0} ({1})", pro_son_list[i], data[i].Y.ToString() + "%");
lbl.Compass = LabelCompassEnum.Radial;
lbl.Offset = 20;
lbl.Connected = true;
lbl.Visible = true;
lbl.AttachMethod = AttachMethodEnum.DataIndex;
AttachMethodData am = lbl.AttachMethodData;
am.GroupIndex = 0;
am.SeriesIndex = i;
am.PointIndex = 0;

}
}

protected void getList(ref string[] pro_son_list, ref int[] pro_son_numlist, ref int allnum)
{
DataSet ds = new DataSet();
DataSet new_ds = new DataSet();
HrCodeStafferDAO daHrCodeStafferDAO = HrCodeStafferDAO.GetInstance("HHHrUserHRServer");

string pro_son = ddlSelectQueryField.SelectedValue;//需要显示得项目
//string addwhere = "";

//获取表里所有数据的条数
allnum = daHrCodeStafferDAO.GetHrCodeStafferListRowCount("");
//获取显示项目dataset(不重复)
ds = daHrCodeStafferDAO.GetDistinctlist(pro_son);
pro_son_list=new string[ds.Tables[0].Rows.Count];
pro_son_numlist = new int[ds.Tables[0].Rows.Count];
int i = 0;
foreach(DataRow dr in ds.Tables[0].Rows)
{
if (dr[pro_son].ToString() != null)
{
string addwhere = " where " + pro_son + " = '" + dr[pro_son].ToString() + "' ";
int pro_son_num = daHrCodeStafferDAO.GetHrCodeStafferListRowCount(addwhere);
pro_son_list[i] = dr[pro_son].ToString();
pro_son_numlist[i] = pro_son_num;
i++;
}
}

}

#endregion
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: