4

我一直在寻找这个问题的答案一两天,但我还没有找到一个。我有一个外部应用程序,它定期修改 TSV 文件(添加数据)。我正在使用基本折线图示例来显示数据,它看起来非常好:

在此处输入图像描述

现在我希望在更新 TSV 文件时更新数据。我希望能够对从 tsv 文件中提取的数据设置自动刷新,并在刷新整个页面的情况下重新填充图表。

我尝试将当前代码包装在一个函数中并在该函数上调用 setInterval,但数据每次都保持不变(可能是因为它被缓存了?)。

理想情况下,这个问题的解决方案是一个可以随时调用更新的函数(基于用户事件、计时器等)。

任何关于实现相同目标的替代方法的想法、链接或建议将不胜感激!

作为一个额外的问题:我知道 D3 可能不是这种伪实时数据显示的正确选择。还有其他更适合这种事情的软件包吗?生成数据的应用程序是 C# 应用程序(以防万一)。

编辑:作为补充说明,想象一下这个例子,但数据是从文件中读取的:http: //mbostock.github.com/d3/tutorial/bar-2.html

4

1 回答 1

0

If you are executing an Ajax call to fetch the data from the server and you think caching is a problem, you can try busting the cache by setting the cache parameter in jquery's ajaxSetup to false anywhere in your code:

$.ajaxSetup({cache: false});

From the docs:

If set to false, it will force requested pages not to be cached by the browser. Note: Setting cache to false will only work correctly with HEAD and GET requests. It works by appending "_={timestamp}" to the GET parameters. The parameter is not needed for other types of requests, except in IE8 when a POST is made to a URL that has already been requested by a GET.

于 2013-01-23T22:29:24.493 回答