简体   繁体   English

实时更新 ajax 图表

[英]Live updating ajax charts

I have a website which serves around 20 - 50 widgets per second and I wanted to create a chart that automatically gets data from the server and then updates the chart and I want the chart to run from right to left as more data is added and remove the old values and add the new values.我有一个网站,每秒提供大约 20 - 50 个小部件,我想创建一个图表,自动从服务器获取数据,然后更新图表,我希望图表在添加和删除更多数据时从右到左运行旧值并添加新值。 I would like a javascript and php solution.我想要一个 javascript 和 php 解决方案。

I have tried google and cannot find any solutions for this and I found a tutorial once but now I have lost that link:( So any kind of help in form of a link, piece of code or what to look for will help.我试过谷歌,找不到任何解决方案,我找到了一个教程,但现在我失去了那个链接:(所以任何形式的链接、代码或要寻找的帮助都会有所帮助。

One thing that I wanted was having the widget start with a delay of fetch data but start displaying the data after 5 seconds of the intial fetch and then fetch data every 2 seconds, however load data second by second.我想要的一件事是让小部件以延迟获取数据开始,但在初始获取 5 秒后开始显示数据,然后每 2 秒获取一次数据,但每秒加载数据。 This would ease the load on the server while also generating smooth graphs.这将减轻服务器上的负载,同时还可以生成平滑的图形。

在此处输入图像描述

Any help would be appreciated....任何帮助,将不胜感激....

Something Like this for php http://support.nevron.com/KB/a175/implement-real-time-chart-in-aspnet-application-using-ajax.aspx php http://support.nevron.com/KB/a175/implement-real-time-chart-in-aspnet-application-using-ajax.aspx这样的东西

So you just need two functions running at different intervals that have access to the same variable where all the data will be stored因此,您只需要两个以不同时间间隔运行的函数,它们可以访问存储所有数据的同一个变量

function runChart() {
  var dataObject = [];

  fetchFromServer = function() {
    //Make your Ajax call here
    //and then update 'dataObject'
  }

  //set fetchFromServer to fire every 5 seconds
  setInterval( function () { fetchFromServer() }, 5000 ); 

  loadToChart = function() {
    //In here keep track of what was the last data you added to the chart
    //pull data-points from 'dataObject' 
    //and display the next data-point on the graph
  }
  //set loadToChart to fire every second
  setInterval( function () { loadToChart() } ,1000); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM