我们正在 Asp.Net 4.5中开发一个实时Web应用程序,其中包含一些图表。
我们还有一个 SQL Server 2008,其中包含一个提供图表的表。
如果找到插入的任何记录具有 X 分钟,则应刷新图表。其中 X 是创建记录后经过的分钟数。例如,如果 X = 20 分钟,我们将以这种方式检查是否有任何记录是 20 分钟前的 getdate(( - table。创建日期 = 20 分钟。
我们已经尝试过使用 SqlDependency
但它有一些限制,例如不允许计算列,所以我们不能做类似的事情
SELECT id,
CASE WHEN DATEDIFF(mi, table.CreationDate, getdate()) = 20 THEN 1
ELSE 0
END Send
FROM table
我们如何做到这一点?
我假设您有一个网页而不是桌面应用程序。
您可以使用 jQuery 每隔 x 秒/分钟获取最新的图表。如果数据库中发生更改,您可以返回新图表,也可以返回 null。
在 jquery 中,检查 json 值是否不为空,设置图表图像。
C# 代码:
public FileContentResult GetYourChartHere()
{
return objCommonFunction.GetYourChartHere();
}
j查询代码:
function GetMyChart() {
$.ajax({
type: 'GET',
url: Path,
cache: false,
success: function (obj) {
//adding a datetime to the querystring allows you to override ajax and browser caching.
var url = Your Page UrL Pointing To'GetYourChartHere' Method + "?t=" + new Date().getTime().toString();
// set the image path for charts
$('#YourImageAttribute').attr('src', url);
},
error: function (obj) {
alert('Something went wrong');
}
});
};