javascript - dygraph从ajax检索数据

标签 javascript dygraphs

generate.php将从mysql中以json格式提取数据。

然后graph.php会通过ajax请求generate.php获取json数据。

我如何使用这个json数据来提供dygraph数据,

示例 dygraph 代码。

g3 = new Dygraph(
document.getElementById("graphdiv3"),
//"temperatures.csv",
          [              //this part i need to change with ajax request data
            [1,10,100],
            [2,20,80],
            [3,50,60],
            [4,70,80]
          ],    
 //jsonStr,
 //data;
 {
   rollPeriod: 7,
   showRoller: true
 }
);

最佳答案

您可以使用 updateOptionsfile 选项来更改图表中的数据,例如:

$.get('/path/to/data', function(data) {
  g.updateOptions({file: data});
});

请参阅dynamic update演示以获取灵感。

关于javascript - dygraph从ajax检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29602667/

相关文章:

javascript - 通过切换类和 CSS 转换在 jquery 中创建移动菜单

javascript - 在 Canvas 中绘制值的百分比。数学-Javascript

javascript - 如果在 jQuery 中再次调用,如何覆盖当前正在运行的函数?

javascript - Dygraph.js - 当 x 为日期时获取图表的中心点

javascript - 将 JSON 与 Dygraph 和日期时间结合使用

javascript - 谷歌地图 JS v3 : Map display: none; after map initialization causing corrupted map

javascript - 对象数组未按正确顺序排序

javascript - Dygraphs 仅显示年份日期值

r - R中dygraph的同步不起作用

javascript - 如何在 iPython Notebook 中渲染 Dygraph?