using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Web.UI.DataVisualization.Charting; using System.Drawing; namespace Chart { public partial class ChartTest : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { GetDataTable get = new GetDataTable(); DataTable dt = get.GetTable(); this.Chart1.DataSource = dt;//綁定數據 this.Chart1.Series["統計量折線"].ChartType = SeriesChartType.Spline;//圖像類型 this.Chart1.Series["統計量折線"].MarkerStyle = MarkerStyle.Cross; this.Chart1.Series[0].XValueMember = "Language";//X軸成員顯示 this.Chart1.Series[0].YValueMembers = "Count";//Y軸成員顯示 this.Chart1.Series[0].IsValueShownAsLabel = true;//顯示座標值 this.Chart1.ChartAreas["ChartArea1"].AxisX.Title = "語言";//X軸標題 //this.Chart1.ChartAreas["ChartArea1"].AxisX.TitleAlignment = System.Drawing.StringAlignment.Far;//X設置對其方式 this.Chart1.ChartAreas["ChartArea1"].AxisY.Title = "統計"; //this.Chart1.ChartAreas["ChartArea1"].AxisY.TitleAlignment = System.Drawing.StringAlignment.Far;//Y設置對其方式 this.Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;//X軸間距 Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;//不顯示豎着的分割線 this.Chart1.DataSource = dt;//綁定數據 this.Chart1.Series["統計量折線圖2"].ChartType = SeriesChartType.Spline;//圖像類型 this.Chart1.Series["統計量折線圖2"].MarkerStyle = MarkerStyle.Cross; this.Chart1.Series[1].XValueMember = "Language";//X軸成員顯示 this.Chart1.Series[1].YValueMembers = "Count";//Y軸成員顯示 this.Chart1.Series[1].IsValueShownAsLabel = true;//顯示座標值 this.Chart1.ChartAreas["ChartArea2"].AxisX.Title = "語言";//X軸標題 //this.Chart1.ChartAreas["ChartArea1"].AxisX.TitleAlignment = System.Drawing.StringAlignment.Far;//X設置對其方式 this.Chart1.ChartAreas["ChartArea2"].AxisY.Title = "統計"; //this.Chart1.ChartAreas["ChartArea1"].AxisY.TitleAlignment = System.Drawing.StringAlignment.Far;//Y設置對其方式 this.Chart1.ChartAreas["ChartArea2"].AxisX.Interval = 1;//X軸間距 Chart1.ChartAreas["ChartArea2"].AxisX.MajorGrid.Enabled = false;//不顯示豎着的分割線 //Chart2.Series["Series1"].Points.DataBind(dt.Rows, "Count", "Language", "LegendText=Language,YValues=Count,ToolTip=Count"); this.Chart2.DataSource = dt;//綁定數據 Chart2.Series["Series1"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Pie;//設置圖表類型 Chart2.Series[0].XValueMember = "Language";//X軸數據成員列 Chart2.Series[0].YValueMembers = "Count";//Y軸數據成員列 //Chart2.Series[0].LegendText = "Language"; Chart2.Series[0].IsValueShownAsLabel = true;//顯示座標值 Chart3.DataSource = dt;//綁定數據 Chart3.Series["Series1"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar;//設置圖表類型 Chart3.Series[0].XValueMember = "Language";//X軸數據成員列 Chart3.Series[0].YValueMembers = "Count";//Y軸數據成員列 Chart3.ChartAreas["ChartArea1"].AxisX.Title = "語言";//X軸標題 Chart3.ChartAreas["ChartArea1"].AxisX.TitleAlignment = StringAlignment.Far;//設置Y軸標題的名稱所在位置位遠 Chart3.ChartAreas["ChartArea1"].AxisY.Title = "統計";//X軸標題 Chart3.ChartAreas["ChartArea1"].AxisY.TitleAlignment = StringAlignment.Far;//設置Y軸標題的名稱所在位置位遠 Chart3.ChartAreas["ChartArea1"].AxisX.Interval = 1;//X軸數據的間距 Chart3.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;//不顯示豎着的分割線 Chart3.Series[0].IsValueShownAsLabel = true;//顯示座標值 } } }