创建折线图x轴日期时间和y轴温度

时间:2016-09-15 17:33:30

标签: c# asp.net charts

我正在使用SQL表“阅读”,其中我有日期时间并记录该实例的温度。 我试图用x轴作为日期时间绘制折线图,​​在y轴上绘制温度。我是在asp.net c#中做的。 现在,datetime实例是随机的。 我尝试了几个例子,但没有运气。 请帮忙。

try
        {
            if (con.State != ConnectionState.Open) con.Open();
            SqlCommand cmd = new SqlCommand("select ReadingInstance,Temprature from Readings", con);

            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
        }
        catch (Exception ex)
        {
        }
        finally
        {
            if (con.State != ConnectionState.Closed) con.Close();
        }

        if (ds.Tables[0].Rows.Count > 0)
        {
            Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
            Chart1.BorderlineColor = System.Drawing.Color.FromArgb(26, 59, 105);
            Chart1.BorderlineWidth = 3;
            Chart1.BackColor = Color.NavajoWhite;

            Chart1.ChartAreas.Add("chtArea");
            Chart1.ChartAreas[0].AxisX.Title = "Category Name";
            Chart1.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("Verdana", 11, System.Drawing.FontStyle.Bold);
            Chart1.ChartAreas[0].AxisY.Title = "UnitPrice";
            Chart1.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("Verdana", 11, System.Drawing.FontStyle.Bold);
            Chart1.ChartAreas[0].BorderDashStyle = ChartDashStyle.Solid;
            Chart1.ChartAreas[0].BorderWidth = 2;
            //Chart1.ChartAreas[0].Area3DStyle.Enable3D = true;
            //Chart1.ChartAreas[0].Area3DStyle.Inclination = 45;
            //Chart1.ChartAreas[0].Area3DStyle.Rotation = 45;
            //Chart1.ChartAreas[0].Area3DStyle.PointDepth = 100;
            //Chart1.ChartAreas[0].Area3DStyle.PointGapDepth = 1;

            Chart1.Legends.Add("Temprature");
            Chart1.Series.Add("Temprature");
            //Chart1.Series[0].Palette = ChartColorPalette.Bright;
            Chart1.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;
            Chart1.Series[0].Points.DataBindXY(ds.Tables[0].DefaultView, "ReadingInstance", ds.Tables[0].DefaultView, "Temprature");

            //Chart1.Series[0].IsVisibleInLegend = true;
            Chart1.Series[0].IsValueShownAsLabel = true;
            Chart1.Series[0].ToolTip = "Data Point Y Value: #VALY{G}";

            // Setting Line Width
            Chart1.Series[0].BorderWidth = 3;
            Chart1.Series[0].Color = Color.Red;

            // Setting Line Shadow
            //Chart1.Series[0].ShadowOffset = 5;

            //Legend Properties
            Chart1.Legends[0].LegendStyle = LegendStyle.Table;
            Chart1.Legends[0].TableStyle = LegendTableStyle.Wide;
            Chart1.Legends[0].Docking = Docking.Bottom;
        }

在aspx.cs和

<asp:Chart ID="Chart1" runat="server" Width="700px" Height="500px"></asp:Chart>
<。>在.aspx

0 个答案:

没有答案