D3.csv cannot climb one directory

I am trying to link to a file located in the parent folder using d3.csv and I cannot find the correct syntax.

My folder structure is as follows:

root
└── js
    ├── data.csv
    └── myGraph.js

In the js folder, I have myGraph.js. In this file, I have the following code snippet:

d3.csv("data.csv", function(error, data) {
   data.forEach(function(d) {
   d.date = parseDate(d.date);
   d.close = +d.close;
});

If I put my data.csv file in the js folder, everything will work fine. However, if I transfer the data.csv file to the root folder

root
├── data.csv
└── js       
    └── myGraph.js

and change the code to this, then it will stop working:

d3.csv("/../data.csv", function(error, data)

I also tried:

d3.csv("../data.csv", function(error, data)

Does anyone know what I'm doing wrong and what is the correct syntax? Many thanks.

+4
source share
1 answer

Robert. To do this, you need to perform several actions:

1) - / , , . - ( -, URL-, d3.csv... ).

2) HTTP- , .js .html. , Python 3 , HTTP- , python -m http.server. http://localhost:8000 , , , , . , -, , .

, , .

+4

Source: https://habr.com/ru/post/1666485/


All Articles