2014-02-24 25 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. 

你必须做的请求的服务器端,而不是客户端。

相关问题