JavaScript图表-动态添加数据点

时间:2022-09-15 10:39:44

I am trying to dynamically add data points to jqplot as a result of AJAX received data, but I do not see a way to accomplish this. Is this not possible?

由于AJAX接收到的数据,我正在尝试动态地向jqplot添加数据点,但是我看不到实现这一点的方法。这是不可能的吗?

If it isn't, what other packages are available that can accomplish the same basic graphing plus allow for dynamic data?

如果不是,还有哪些包可以实现同样的基本图形化plus,从而支持动态数据?

1 个解决方案

#1


6  

You may want to check the example below on how this is handled in Flot. Flot is an open-source plotting library based on jQuery, like jqplot. Both libraries are very similar.

您可能想要查看下面的示例,了解如何在Flot中处理这个问题。Flot是一个基于jQuery的开源绘图库,像jqplot。这两个库非常相似。

This is how fetching and plotting the data with AJAX would look like in code:

这就是使用AJAX获取和绘制数据的代码:

function fetchData() {
   $.ajax({
      url:      "json_fetch_new_data.php",
      method:   "GET",
      dataType: "json",
      success:  function(series) {
         var data = [ series ];

         $.plot($("#placeholder"), data, options);
      }
   });

   setTimeout(fetchData, 1000);
}

Make sure to check the following demo to see it in action:

确保检查下面的演示程序以查看它的运行情况:

For further information on Flot:

有关Flot的进一步资料:

#1


6  

You may want to check the example below on how this is handled in Flot. Flot is an open-source plotting library based on jQuery, like jqplot. Both libraries are very similar.

您可能想要查看下面的示例,了解如何在Flot中处理这个问题。Flot是一个基于jQuery的开源绘图库,像jqplot。这两个库非常相似。

This is how fetching and plotting the data with AJAX would look like in code:

这就是使用AJAX获取和绘制数据的代码:

function fetchData() {
   $.ajax({
      url:      "json_fetch_new_data.php",
      method:   "GET",
      dataType: "json",
      success:  function(series) {
         var data = [ series ];

         $.plot($("#placeholder"), data, options);
      }
   });

   setTimeout(fetchData, 1000);
}

Make sure to check the following demo to see it in action:

确保检查下面的演示程序以查看它的运行情况:

For further information on Flot:

有关Flot的进一步资料: