标签:
感谢csdn深南大道,文章转自http://blog.csdn.net/smartsmile2012/article/details/17356673
前台代码
<div> <asp:Chart ID="Chart1" runat=server> <Series> <asp:Series Name="Series1"></asp:Series> </Series> <ChartAreas> <asp:ChartArea Name="ChartArea1"></asp:ChartArea> </ChartAreas> </asp:Chart> <asp:Chart ID="Chart2" runat=server><Series><asp:Series Name="Series1"></asp:Series></Series><ChartAreas><asp:ChartArea Name="ChartArea1"></asp:ChartArea></ChartAreas></asp:Chart> <asp:Chart ID="Chart3" runat=server><Series><asp:Series Name="Series1"></asp:Series></Series><ChartAreas><asp:ChartArea Name="ChartArea1"></asp:ChartArea></ChartAreas></asp:Chart> </div>
后台代码
System.Data.DataTable dt = CreatData(); GetStyle4(dt); GetStyle2(dt); GetStyle3(dt); } protected System.Data.DataTable CreatData() { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add("Country", System.Type.GetType("System.String")); dt.Columns.Add("Score", System.Type.GetType("System.String")); string[] n = new string[] { "中国","美国", "俄罗斯", "英国" }; string[] c = new string[] { "85","80", "50", "35" }; for (int i = 0; i < 4; i++) { DataRow dr = dt.NewRow(); dr["Country"] = n[i]; dr["Score"] = c[i]; dt.Rows.Add(dr); } return dt; } protected void GetStyle3(System.Data.DataTable dt) { Chart3.DataSource = dt;//绑定数据 Chart3.Series["Series1"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;//设置图表类型 Chart3.Series[0].XValueMember = "Country";//X轴数据成员列 Chart3.Series[0].YValueMembers = "Score";//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;//显示坐标值 } protected void GetStyle2(System.Data.DataTable dt) { Chart2.DataSource = dt;//绑定数据 Chart2.Series["Series1"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar;//设置图表类型 Chart2.Series[0].XValueMember = "Country";//X轴数据成员列 Chart2.Series[0].YValueMembers = "Score";//Y轴数据成员列 Chart2.ChartAreas["ChartArea1"].AxisX.Title = "语言";//X轴标题 Chart2.ChartAreas["ChartArea1"].AxisX.TitleAlignment = StringAlignment.Far;//设置Y轴标题的名称所在位置位远 Chart2.ChartAreas["ChartArea1"].AxisY.Title = "统计";//X轴标题 Chart2.ChartAreas["ChartArea1"].AxisY.TitleAlignment = StringAlignment.Far;//设置Y轴标题的名称所在位置位远 Chart2.ChartAreas["ChartArea1"].AxisX.Interval = 1;//X轴数据的间距 Chart2.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;//不显示竖着的分割线 Chart2.Series[0].IsValueShownAsLabel = true;//显示坐标值 } protected void GetStyle4(System.Data.DataTable dt) { Chart1.DataSource = dt;//绑定数据 Chart1.Series["Series1"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Pie;//设置图表类型 Chart1.Series[0].XValueMember = "Country";//X轴数据成员列 Chart1.Series[0].YValueMembers = "Score";//Y轴数据成员列 Chart1.Series[0].LegendMapAreaAttributes = "Country"; //显示国家 Chart1.Series[0].IsValueShownAsLabel = true;//显示坐标值 }
标签:
原文地址:http://www.cnblogs.com/yuanjiehot/p/4395035.html