echarts怎么設(shè)置數(shù)據(jù)自動(dòng)排序?
數(shù)據(jù)都是通過(guò)sql語(yǔ)句排序的
1.Echarts柱狀圖的正常配置
注:聲明了 myChart、test這兩個(gè)都有用
官方示例中myChart是聲明在 function(ec)里面的
2.添加 refreshData函數(shù)
在第一步放在函數(shù)外面的myChart和test都會(huì)在refreshData函數(shù)里面用上
注:option.series[0].data = data;這句的格式最重要
3.使用window.setInterval 來(lái)實(shí)現(xiàn)自動(dòng)刷新數(shù)據(jù)
用了jQuery的,所以在第一句就引用了jQuery
4.SQLTest.ashx
1.ContentType設(shè)置為text/plain
2.直接把需要返回的數(shù)據(jù) write回來(lái)即可
using System;
using System.Web;
using DAL;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
public class SQLTest : IHttpHandler {
SQLHelper SQLAss = new SQLHelper();
string StrCon = ConfigurationManager.ConnectionStrings["DatabaseTest"].ConnectionString;
static int i=1;
public void ProcessRequest (HttpContext context)
{
context.Response.ContentType = "text/plain";
string sqlstr = "SELECT Progress FROM T_EchartData1 WHERE Num LIKE '" + i.ToString() + "'";
//SELECT Age FROM Person1 WHERE id = '2' SQL可以用等號(hào)
var dt = SQLAss.ExecuteQuery(sqlstr, CommandType.Text);//將讀取的數(shù)據(jù)存到dt里面
i++;
if (i >= 6) i = 1;
context.Response.Write(Convert.ToInt32(dt.Rows[0][0].ToString()));
}
public bool IsReusable {
get {
return false;
}
}
}