日期:2014-05-20 浏览次数:20771 次
private void InitializeComponent() { this.ZedGraphWeb1.RenderGraph += new ZedGraphWebControlEventHandler(this.OnRenderGraph1); this.Load += new System.EventHandler(this.Page_Load); } private void OnRenderGraph1(ZedGraphWeb zgw, Graphics g, MasterPane masterPane) { GraphPane myPane = masterPane[0]; myPane.YAxis.Scale.Max = 60; myPane.YAxis.Scale.Min = 0; myPane.XAxis.MajorGrid.IsVisible = true; myPane.YAxis.MajorGrid.IsVisible = true; myPane.XAxis.MajorGrid.Color = Color.LightGray; myPane.YAxis.MajorGrid.Color = Color.LightGray; myPane.XAxis.MajorGrid.DashOff = 0; myPane.YAxis.MajorGrid.DashOff = 0; myPane.YAxis.Scale.BaseTic = -40; myPane.XAxis.Scale.MajorStep = 10; myPane.XAxis.Scale.MinorStep = 2.5; myPane.YAxis.Scale.MajorStep = 10; myPane.YAxis.Scale.MinorStep = 2.5; myPane.YAxis.Scale.IsVisible = true; myPane.Title.Text = "温度曲线图"; myPane.XAxis.Title.Text = "时间"; myPane.YAxis.Title.Text = "温度"; DataSourcePointList dspl = new DataSourcePointList(); dspl.DataSource = GetData().Tables[0]; dspl.XDataMember = "Timestamp"; dspl.YDataMember = "Air_Temperature"; dspl.ZDataMember = null; LineItem myCurve2 = myPane.AddCurve("温度℃", dspl, Color.LightGray, SymbolType.Plus); myPane.XAxis.Type = AxisType.Date; myPane.XAxis.CrossAuto = true; myPane.Chart.Fill = new Fill(Color.Black, Color.Black, 45F); masterPane.AxisChange(g); } private void BindData() { SqlConnection sqlcon = new SqlConnection(); try { sqlcon.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DB_CON"].ConnectionString; sqlcon.Open(); SqlCommand sqlcom = new SqlCommand(); sqlcom.Connection = sqlcon; sqlcom.CommandText = "select top 10 Air_Temperature as 气温 from Weather order by Timestamp desc"; sqlcom.CommandType = CommandType.Text; SqlDataAdapter sqlda = new SqlDataAdapter(sqlcom); ds = new DataSet(); sqlda.Fill(ds); GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); } catch (Exception ex) { throw (ex); } finally { sqlcon.Close(); } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindData(); } InitializeComponent(); }