View Code
1 public partial class WebForm1 : System.Web.UI.Page 2 { 3 protected void Page_Load(object sender, EventArgs e) 4 { 5 if (!IsPostBack) 6 { 7 CreateChart(); 8 } 9 } 10 11 public DataTable GetTempData() 12 { 13 string strSql = "SELECT * FROM ChartDB"; 14 SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DEMO;Integrated Security=True"); 15 SqlDataAdapter da = new SqlDataAdapter(strSql, con); 16 DataSet ds = new DataSet(); 17 da.Fill(ds); 18 return ds.Tables[0]; 19 } 20 21 public void CreateChart() 22 { 23 Chart1.Width = 600; 24 Chart1.Height = 400; 25 Chart1.ChartAreas[0].AxisX.LineWidth = 3; 26 Chart1.ChartAreas[0].AxisY.LineWidth = 3; 27 Chart1.DataSource = GetTempData(); 28 Series s1 = new Series(); 29 s1.IsValueShownAsLabel = true; 30 s1.ChartType = SeriesChartType.Line; 31 s1.MarkerStyle = MarkerStyle.Circle; 32 s1.MarkerSize = 6; 33 Chart1.Series.Add(s1); 34 Series s2 = new Series(); 35 s2.ChartType = SeriesChartType.Line; 36 s2.MarkerStyle = MarkerStyle.Cross; 37 s2.MarkerSize = 6; 38 s2.IsValueShownAsLabel = true; 39 Chart1.Series.Add(s2); 40 Legend l = new Legend(); 41 l.Docking = Docking.Bottom; 42 l.Alignment = System.Drawing.StringAlignment.Center; 43 l.LegendStyle = LegendStyle.Row; 44 Chart1.Legends.Add(l); 45 Legend l2 = new Legend(); 46 l2.Docking = Docking.Bottom; 47 l2.Alignment = System.Drawing.StringAlignment.Center; 48 l2.LegendStyle = LegendStyle.Row; 49 Chart1.Legends.Add(l2); 50 Legend l1 = new Legend(); 51 l1.LegendStyle = LegendStyle.Row; 52 l1.Docking = Docking.Bottom; 53 l1.Alignment = System.Drawing.StringAlignment.Center; 54 Chart1.Legends.Add(l1); 55 Chart1.Series[0].ChartType = SeriesChartType.Line; 56 Chart1.Series[0].XValueMember = "Worker"; 57 Chart1.Series[0].YValueMembers = "ProductPrice"; 58 Chart1.Series[0].LegendText = "日收入"; 59 Chart1.Series[1].XValueMember = "Worker"; 60 Chart1.Series[1].YValueMembers = "YearPrice"; 61 Chart1.Series[1].LegendText = "年收入"; 62 Chart1.Series[2].XValueMember = "Worker"; 63 Chart1.Series[2].YValueMembers = "MonthPrice"; 64 Chart1.Series[2].LegendText = "月收入"; 65 Chart1.DataBind(); 66 } 67 }
怀揣着一点点梦想的年轻人
相信技术和创新的力量
喜欢快速反应的工作节奏
相信技术和创新的力量
喜欢快速反应的工作节奏