Home › forums › Using CanvasJS › Code from "Creating Charts from CSV" is not working in my HTML document
This topic contains 4 replies, has 2 voices, and was last updated by sepetar 4 months, 1 week ago.
If I copy your working code in my text editor (Notepad++) from your document “Creating Charts from CSV”
and then save this code as HTML document, after that in my browser I have nothing (empty screen) !
The browser gives me following error message:
” Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://canvasjs.com/services/data/datapoints.php?xstart=5&ystart=10&length=10&type=csv. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).”
Help me to understand how to use this code in my HTML document.
Also I’d like to know how to use local CSV file (from my hard disk)
with this code !
For security reasons, browsers restrict cross-origin requests. Please refer to this StackOverflow post for more information. Serving CSV file from a local web server and making an AJAX call to it or serving it from CORS enabled CSV hosting should work fine in this case.
Also, it’s not possible to load CSV data from the local machine unless it’s served from a local web server or from the same domain where HTML is hosted. It’s basically a browser restriction for security reasons. Please refer to the above link for more info on Cross-Origin Requests.
I am a bit confused with your answer about impossibility to load CSV data from the local machine unless it’s served from a local web server.
I found this code in “http://jsfiddle.net/3hmee6vb/3/” . With this code is possible to load CSV data from local machine. I suppose it is possible to use those data with CanvasJS ?
I am sorry if my question is not appropriate.
It’s not possible to directly load a file via AJAX request. However, you can load/browse the file from local disk. Once the file is loaded, parsing it to the format accepted by CanvasJS should work fine. Please refer to this documentation page for the step-to-step tutorial on parsing CSV data and rendering the chart.
Thanks Shashi Ranjan !
You must be logged in to reply to this topic.