失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Asp.net之MsChart控件动态绑定温度曲线图

Asp.net之MsChart控件动态绑定温度曲线图

时间:2020-12-12 01:45:19

相关推荐

Asp.net之MsChart控件动态绑定温度曲线图

<div><div style="position: absolute; z-index: 200; background-color: #FFFFFF; height: 130px;width: 47px; top: 168px; left: 10px;"><br /><br /><span style="color: Red; font-size: 12px;">最高(℃)</span> </br></br><span style="color: Blue; font-size: 12px;">最低(℃)</span></div><div style="position: absolute; z-index: 30; height: 119px; width: 729px; left: 31px;"><asp:Chart ID="Chart1" runat="server" Height="145px" IsSoftShadows="False" Palette="None"Style="margin-left: 0px" Width="729px"><Series><asp:Series ChartArea="ChartArea1" ChartType="Line" IsValueShownAsLabel="True" MarkerSize="10"MarkerStyle="Circle" Name="Series2" BorderColor="Red" LabelBorderColor="Transparent"MarkerBorderColor="Transparent" MarkerColor="Red"></asp:Series><asp:Series ChartArea="ChartArea1" ChartType="Line" IsValueShownAsLabel="True" MarkerSize="10"MarkerStyle="Circle" Name="Series4" BorderColor="Blue" MarkerColor="Blue"></asp:Series></Series><ChartAreas><asp:ChartArea Name="ChartArea1"></asp:ChartArea></ChartAreas></asp:Chart></div></div>

前台设计

string conn = ConfigurationManager.AppSettings["ConnectionString1"].ToString();DataTable dtTable = new DataTable();protected void Page_Load(object sender, EventArgs e){double[] xValues = { 1, 2, 3, 4, 5, 6, 7 };GetData();Chart1.DataSource = dtTable;int len = dtTable.Rows.Count;double[] yValues = new double[len];double[] y2Values = new double[len];for (int i = 0; i < dtTable.Rows.Count; i++){yValues[i] =Convert.ToDouble( dtTable.Rows[i]["Temperature_max_60"].ToString());y2Values[i] = Convert.ToDouble( dtTable.Rows[i]["Temperature_min_60"].ToString());}Chart1.Series["Series2"].Points.DataBindXY(xValues, yValues);Chart1.Series["Series4"].Points.DataBindXY(xValues, y2Values);Chart1.ChartAreas["ChartArea1"].Position.X = 0;Chart1.ChartAreas["ChartArea1"].Position.Y = 0;Chart1.ChartAreas["ChartArea1"].Position.Height = 100;Chart1.ChartAreas["ChartArea1"].Position.Width = 100;Chart1.ChartAreas["ChartArea1"].AxisX.Minimum = 1;Chart1.ChartAreas["ChartArea1"].AxisX.Maximum = 7.05;Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;Chart1.ChartAreas["ChartArea1"].AxisX.IntervalAutoMode = IntervalAutoMode.FixedCount;Chart1.ChartAreas["ChartArea1"].BorderColor = Color.Gray;Chart1.ChartAreas["ChartArea1"].AxisX.LineColor = Color.Gray;Chart1.ChartAreas["ChartArea1"].AxisY.LineColor = Color.Gray;Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.Gray;Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.Gray;Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.ForeColor = Color.Transparent;Chart1.ChartAreas["ChartArea1"].AxisY.LabelStyle.ForeColor = Color.Transparent;Chart1.Series["Series2"].Color = Color.Red;Chart1.Series["Series4"].Color = Color.Blue;}public DataTable GetData(){SqlConnection con = new SqlConnection(conn);con.Open();string strsql = "SELECT top 7 CollectDate, zdz_min .Station, Temperature, Temperature_max_60, Temperature_max_time, Temperature_min_60, Temperature_min_time, AirPressure, Rain_sum_60, RelativeHumidity, RelativeHumidity_min_60, RelativeHumidity_min_time, WindDirection, WindSpeed, WindDirection_aver_2, WindSpeed_aver_2, WindDirection_Flurry_max, WindSpeed_Flurry_max, Wind_Flurry_max_time, Visibility, Visibility_min_60 FROM zdz_min where station between 98000 and 99501 or station =58366 order by zdz_min.CollectDate desc";SqlCommand cmd = new SqlCommand(strsql, con);SqlDataAdapter sda = new SqlDataAdapter(cmd);sda.Fill(dtTable);return dtTable;}

后台代码

如果觉得《Asp.net之MsChart控件动态绑定温度曲线图》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。