Question

I am trying to create a chart from historical stock information, retrieved from Yahoo Finance, using Dygraphs.

The url I am trying to use as source of data is: 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

When I include the code below in my HTML file, I do not get any error message with Firebug. Yet the chart is empty.

Could anyone help me explain what I am doing wrong?

<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

Was it helpful?

Solution

You're running into the same-origin policy for XmlHttpRequest.

When I run your code in jsfiddle, I see this error in the Chrome Developer Console:

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.

You'll have to do the request server-side, rather than client-side.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top