Real Time data graph [closed]

淺唱寂寞╮ 提交于 2019-12-18 10:33:48

问题


I would like to build a web-based real time data graph and i'm looking at the different options such as:

  • Html5 canvas
  • JS libraries with graph support such as Extjs

By real time i mean, either the client polling the web server say every second or using reverse ajax; the server pushes data to the client when available.

Can you please recommend any?


回答1:


You may want to consider using Flot, an open-source plotting library based on jQuery.

I'm assuming that by real-time you mean that the graph will update automatically. The following is how your code would look like if you were to fetch and plot the data using AJAX polling at 1 second intervals:

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 out the following demo to see it in action (Click on the "Poll for Data" button):

  • Flot Examples - Updating graphs with AJAX

For further information on Flot:

  • Flot Project Site
  • Flot Examples
  • Other Flot Examples



回答2:


There is also SmoothieCharts that is designed more for this use-case.




回答3:


Other solution with design more nice and possibilities:

https://changelog.com/posts/rickshaw-realtime-javascript-graphing-library

example: http://shutterstock.github.com/rickshaw/examples/extensions.html

code: https://github.com/shutterstock/rickshaw



来源:https://stackoverflow.com/questions/3792750/real-time-data-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!