zoukankan      html  css  js  c++  java
  • Asp.net之MsChart控件动态绑定温度曲线图

    <div>
            <div style="position: absolute; z-index: 200; background-color: #FFFFFF; height: 130px;
                 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;  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;
            }
    后台代码
  • 相关阅读:
    面向对象并不是必要的
    linq 总结
    垃圾自动回收的一个方案
    随手记 手机软件的不足,和开发自己理财软件的想法
    以人的角度去解决问题
    浮点数比较
    集中原则——软件设计之道
    云在何方
    我遇到了DLL地狱
    在C#.net中如何操作XML
  • 原文地址:https://www.cnblogs.com/652769324qq/p/3192653.html
Copyright © 2011-2022 走看看