标签:ati command 一个 运行 head ring tail har body
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="Home.aspx.cs" Inherits="VisualData.Home" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="ChartJS.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Literal ID="ltChart" runat="server"></asp:Literal>
</div>
</form>
</body>
</html>
string
若要连接到MS SQL Server数据库,请执行以下操作:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="myConnection" connectionString="Data Source=.\mySQLInstance;
initial catalog=myDatabaseName; user id=myUsername; password=myPassword;"/>
</connectionStrings>
</configuration>
private void ShowData()
{
String myConnection = ConfigurationManager.ConnectionStrings["myConnection"].ToString();
SqlConnection con = new SqlConnection(myConnection);
String query = "Select top 100 AirTemperature
From tbWeathers Where stationID=1 order by id desc";
SqlCommand cmd = new SqlCommand(query, con);
DataTable tb = new DataTable();
try
{
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
tb.Load(dr, LoadOption.OverwriteChanges);
con.Close();
}
catch { }
if(tb != null)
{
String chart = "";
// You can change your chart height by modify height value
chart = "<canvas id=\"line-chart\"
width=\"100%\" height=\"40\"></canvas>";
chart += "<script>";
chart += "new Chart(document.getElementById(\"line-chart\"),
{ type: ‘line‘, data: {labels: [";
// more details in x-axis
for (int i = 0; i < 100; i++)
chart += i.ToString() + ",";
chart = chart.Substring(0, chart.Length - 1);
chart += "],datasets: [{ data: [";
// put data from database to chart
String value = "";
for (int i = 0; i < tb.Rows.Count; i++)
value += tb.Rows[i]["NhietDo"].ToString() + ",";
value = value.Substring(0, value.Length - 1);
chart += value;
chart += "],label: \"Air Temperature\",
borderColor: \"#3e95cd\",fill: true}"; // Chart color
chart += "]},options: { title: { display: true,text:
‘Air Temperature (oC)‘} }"; // Chart title
chart += "});";
chart += "</script>";
ltChart.Text = chart;
}
}
使用ASP.NET中的Chart.js在ASP.NETVisual数据中使用Chart.js的可视化数据
标签:ati command 一个 运行 head ring tail har body
原文地址:https://www.cnblogs.com/cddehsy/p/9613264.html