2017-07-18 38 views
0

我試圖測試D3的d3.csv()CSV閱讀功能,但仍然收到錯誤的JavaScript d3.csv()給出了錯誤:讀ECONNRESET

{ 'Error: read ECONNRESET': ' at exports._errnoException (util.js:1050:11)' }

我的測試腳本test1.js是反應app目錄。

admin:reactStockCharts jvr23$ tree -L 1 
. 
├── BCHARTS-BITSTAMPUSD.csv 
├── README.md 
├── node_modules 
├── package-lock.json 
├── package.json 
├── public 
├── reactStockCharts.sublime-project 
├── reactStockCharts.sublime-workspace 
├── src 
└── test1.js 

測試csv文件BCHARTS-BITSTAMPUSD.csv駐留在同一目錄中。內容如下:

Date,Open,High,Low,Close,Volume (BTC),Volume (Currency),Weighted Price 
2017-07-11,2326.12,2399.0,2242.62,2336.78,16815.9742946,39367980.6825,2341.10614068 
2017-07-10,2504.0,2527.88,2261.85,2323.45,17296.3404527,41650843.7716,2408.07261429 
2017-07-09,2550.13,2564.65,2500.5,2502.28,4483.14413363,11362427.9698,2534.47750755 
2017-07-08,2501.46,2555.0,2462.0,2550.07,5405.89088691,13584489.5168,2512.90486637 
2017-07-07,2599.01,2605.0,2475.0,2501.46,9430.6154578,23870564.3605,2531.17778658 

test1.js腳本內容:

var d3 = require("d3"); 

d3.csv("BCHARTS-BITSTAMPUSD.csv", function(err, data) { 
    console.log(err); 
    console.log(data[0]); 
}); 

執行該腳本然後給

admin:reactStockCharts jvr23$ node test1.js 
null 
{ 'Error: read ECONNRESET': ' at exports._errnoException (util.js:1050:11)' } 

D3的包經$ npm i d3之前成功地安裝。

回答

0

我能夠用全路徑規格更換

var d3 = require("d3"); 

d3.csv("BCHARTS-BITSTAMPUSD.csv", function(err, data) { 
    console.log(err); 
    console.log(data[0]); 
}); 

來解決該問題

var d3 = require("d3"); 

d3.csv("file:///full/path/to/BCHARTS-BITSTAMPUSD.csv", function(err, data) { 
    console.log(err); 
    console.log(data); 
}); 
+0

您的意思是指定一個'本地'路徑?如果是這樣,如果你去住了會發生什麼? –

+0

我只需要獲取一些示例csv數據來反應stockchart組件。這個解決方案不會生活。 –

+0

哦。得到它了.... –