2014-09-02 113 views
0

如果我.csv文件放在同一文件夹中dygraph-combined.js - 在/ var/WWW - 然后将图形绘制,见下图:Dygraph文件路径

g = new Dygraph(
     document.getElementById("graphdiv"), 
     "meterLogPercentageThreshold.csv", // path to .csv file 
     { 
      rollPeriod: 1, 
      showRoller: true, 
      fillGraph: false, 
      ylabel: 'Power (W/h)', 
      xlabel: 'Date and Time', 
      showRangeSelector: true, 
      colors: ['#00aa00'] 
     } 
    ); 

但如果我指定了其他位置,然后图表不绘制,请有人指出我在正确的方向?

???这不起作用,它是同一个文件,我知道我在做一些愚蠢的事情,只是不知道是什么?

g = new Dygraph(
     document.getElementById("graphdiv"), 
     "/media/Power/meterLogPercentageThreshold.csv", // path to .csv file 
     { 
      rollPeriod: 1, 
      showRoller: true, 
      fillGraph: false, 
      ylabel: 'Power (W/h)', 
      xlabel: 'Date and Time', 
      showRangeSelector: true, 
      colors: ['#00aa00'] 
     } 
    ); 

回答

0

如果你在一个URL传递,dygraphs会发出它一个XMLHttpRequest,并试图解析返回的数据为CSV。

认识到你使用的是网址而不是目录很重要。此网址是服务器上文件的地址。您必须确保URL可以访问并以文本格式返回数据。

2个可能的解决方案:

  • 将在/var/www文件并指定此文件夹中的文件的相对路径。
  • 将一个url放到服务器脚本文件中,例如.asp和.php,它们在发送响应之前在服务器上执行操作。在这些脚本文件中,您可以从本地文件系统获取文件并以文本格式返回数据。