日期:2014-05-18 浏览次数:21224 次
GraphPane myPan = new GraphPane(); PointPairList list = new PointPairList(); Random ran = new Random(); LineItem myCurve; DataSet ds = new DataSet(); SqlConnection myConnection = null; SqlCommand myCommand = null; SqlDataAdapter adapt = null; SqlDataReader reader = null; public Form1() { InitializeComponent(); } public string GetConnectString(string server, string database, string username, string password) { return "Server=" + server + ";Database=" + database + ";UID=" + username + ";PWD=" + password; } public void Exc() { double x, y; myConnection = new SqlConnection(); myConnection.ConnectionString = GetConnectString("192.168.0.101", "AMR", "sa", "123"); myCommand = new SqlCommand("select MSID,UpdateTime from Tab_BS_Dailyfile", myConnection); myCommand.CommandType = CommandType.Text; myConnection.Open(); adapt = new SqlDataAdapter(); try { //myCommand.ExecuteNonQuery(); reader = myCommand.ExecuteReader(); while (reader.Read()) { for (int i = 0; i < reader.FieldCount; ) { y = double.Parse(reader[i++].ToString()); x = (double)new XDate(DateTime.Parse(reader[i++].ToString())); list.Add(x, y); } } } catch (SqlException ex) { MessageBox.Show("插入错误!" + ex.Message.ToString()); } myCommand.Clone(); myConnection.Close(); } private void Form1_Load(object sender, EventArgs e) { this.zedGraphControl1.GraphPane.Title.Text = "动态折线图"; this.zedGraphControl1.GraphPane.XAxis.Title.Text = "时间"; this.zedGraphControl1.GraphPane.X2Axis.Scale.FontSpec.Size = 28; this.zedGraphControl1.GraphPane.YAxis.Title.Text = "数量"; this.zedGraphControl1.GraphPane.YAxis.Scale.FontSpec.Size = 8; myPan.XAxis.Scale.IsVisible = true; this.zedGraphControl1.GraphPane.XAxis.Type = ZedGraph.AxisType.DateAsOrdinal; Exc(); DateTime dt = DateTime.Now; myCurve = zedGraphControl1.GraphPane.AddCurve("My Curve", list, Color.DarkGreen, SymbolType.None); this.zedGraphControl1.AxisChange(); this.zedGraphControl1.Refresh(); }