原創|其它|編輯:郝浩|2012-10-15 16:10:30.000|閱讀 572 次
概述:主要講解了如何在ASP.NET中使用Teechart畫餅形圖、柱形圖,提供示例源碼和大家分享一下
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
最近在學習如何使用在ASP.NET中使用Teechart圖表控件畫餅形圖、柱形圖,下面是做的示例的源碼,和大家分享一下
源碼如下:
private void Page_Load(object sender, System.EventArgs e) { // 在此處放置用戶代碼以初始化頁面 if(!Page.IsPostBack) { this.txtStart.Text =DateTime.Now.Year.ToString(); this.txtEnd.Text =DateTime.Now.Year.ToString(); int m=Convert.ToInt16(DateTime.Now.Month.ToString()); this.ddlEnd.SelectedIndex =m-1; //當前月份 } if ((this.txtStart.Text=="")||(this.txtEnd.Text=="")) { Response.Write("<script language='javascript'>alert('"+"年月份都不能為空!"+"')</script>"); return; } if (this.txtStart.Text==this.txtEnd.Text) //年份相等 { if(Convert.ToInt16(this.ddlStart.SelectedItem.Text)>Convert.ToInt16(this.ddlEnd.SelectedItem.Text)) { Response.Write("<script language='javascript'>alert('"+"起始年月應該不大于截至年月!"+"')</script>"); return; } } if (Convert.ToInt16(this.txtStart.Text)>Convert.ToInt16(this.txtEnd.Text)) { Response.Write("<script language='javascript'>alert('"+"起始年份應該不大于截至年份!"+"')</script>"); return; } this.DrawPie(); } private void DrawPie() { WebChart1.Chart.Panel.Color = System.Drawing.Color.AliceBlue; WebChart1.Chart.Legend.LegendStyle = Steema.TeeChart.LegendStyles.Auto; WebChart1.Chart.Legend.Alignment = Steema.TeeChart.LegendAlignments.Bottom; WebChart1.Chart.Legend.Inverted = true; WebChart1.Chart.Legend.ShapeStyle = Steema.TeeChart.Drawing.TextShapeStyle.RoundRectangle; WebChart1.Chart.Legend.Symbol.Visible = true; WebChart1.Chart.Legend.Font.Color = System.Drawing.Color.DarkBlue; WebChart1.Dispose(); string chartTitle = "公司機械租賃費示意圖"; WebChart1.Chart.Header.Text = chartTitle.Trim().ToString(); WebChart1.Chart.Axes.Left.Title.Text = "公司機械租賃費示意圖"; Steema.TeeChart.Styles.Pie Pie1 = new Steema.TeeChart.Styles.Pie(); WebChart1.Chart.Series.Add(Pie1); DataSet dsall = DBSQL.GetDataSet("select 項目部編號,項目部,sum(租賃費) as 金額 from JX_TenancyBal where 單據類型=0 "+ " and 結算年度>='"+(this.txtStart.Text).Trim()+"'and 結算年度<='"+(this.txtEnd.Text).Trim()+"' and 結算月度>='"+this.ddlStart.SelectedItem.Text +"' and 結算月度<='"+this.ddlEnd.SelectedItem.Text+"' group by 項目部編號,項目部"); Pie1.DataSource = dsall.Tables[0]; Pie1.YValues.DataMember = dsall.Tables[0].Columns[2].ToString(); Pie1.LabelMember = dsall.Tables[0].Columns[1].ToString(); WebChart1.DataBind(); } private void btnDrawPie_Click(object sender, System.EventArgs e) { this.DrawPie(); } private void DrawBar() { Steema.TeeChart.Styles.Bar Bar1 ; DataSet DS = new DataSet(); WebChart1.Chart.Header.Text = "公司機械租賃費示意圖"; WebChart1.Chart.Axes.Left.Title.Text = "公司機械租賃費示意圖"; WebChart1.Dispose(); Bar1 = new Steema.TeeChart.Styles.Bar(WebChart1.Chart); Bar1.ColorEach = true; //WebChart1.Chart.Axes.Bottom.Title.Text = "公司機械租賃費示意圖"; string SelectStr ="select 項目部編號,項目部,sum(租賃費) as 金額 from JX_TenancyBal where 單據類型=0 "+ " and 結算年度>='"+(this.txtStart.Text).Trim()+"'and 結算年度<='"+(this.txtEnd.Text).Trim()+"' and 結算月度>='"+this.ddlStart.SelectedItem.Text +"' and 結算月度<='"+this.ddlEnd.SelectedItem.Text+"' group by 項目部編號,項目部 order by 項目部編號"; DS.Clear(); try { DS = DBSQL.GetDataSet(SelectStr); } catch {} Bar1.DataSource = DS.Tables[0]; Bar1.YValues.DataMember = DS.Tables[0].Columns[2].ToString(); Bar1.LabelMember=DS.Tables[0].Columns[1].ToString(); WebChart1.DataBind(); } private void Button2_Click(object sender, System.EventArgs e) { this.DrawBar(); }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:新浪博客