2014-02-24 27 views
0

我正在嘗試使用Dygraphs從Yahoo Finance獲取的歷史股票信息創建圖表。是否可以使用Dygraphs繪製來自此網頁的數據?

我想作爲數據源使用的URL是: http://ichart.finance.yahoo.com/table.csv?s=UL.PA&a=08&b=7&c=1984&d=01&e=24&f=2014&g=d&ignore=.csv

當我包括我的HTML文件下面的代碼,我沒有得到任何錯誤消息螢火蟲。但圖表是空的。

任何人都可以幫我解釋我做錯了什麼嗎?

<div id="graphdiv"></div> 
<script type="text/javascript"> 
    g = new Dygraph(document.getElementById("graphdiv"),"http://ichart.finance.yahoo.com/table.csv?s=UL.PA&amp;a=08&amp;b=7&amp;c=1984&amp;d=01&amp;e=24&amp;f=2014&amp;g=d&amp;ignore=.csv",{}); 
</script> 

LC

回答

1

您正在運行到same-origin policy的XmlHttpRequest的。

當我運行中的jsfiddle你的代碼,我看到在Chrome開發者控制檯此錯誤:

XMLHttpRequest cannot load http://ichart.finance.yahoo.com/table.csv?s=UL.PA&amp;a=08&amp;b=7&amp;c=1984&amp;d=01&amp;e=24&amp;f=2014&amp;g=d&amp;ignore=.csv. 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://fiddle.jshell.net' is therefore not allowed access. 

你必須做的請求的服務器端,而不是客戶端。

相關問題