Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript D3.js Data Binding with D3.js Request Methods

How do I get d3.csv() or d3.json() to work outside of the workspace?

When I try to use d3.csv() or d3.json() with local files, I get an error in the console. "Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource."

Code:

 d3.csv('climate_data.csv', function(data) {
    debugger;
 });

Or

 d3.json('phones.json', function(error, data) {
    // do something with the data here
    console.log(error);
    console.log(data);
 });

The files are stored locally.

Daniel Giraldo
Daniel Giraldo
13,396 Points

In order to get these files to work locally you will need to use an HTTP server. Personally I like to use MAMP.

Hope that helps :)