簡體   English   中英

如何在AngularJS中使用D3加載節點服務器的tsv文件

[英]How can I load tsv file of node server using D3 in AngularJS

我已經使用AngularJS,D3.js和node.js練習了數據的可視化。

我的應用程序結構如下。

Application/
  client/
    app/
      app.js
      index.html
      dashboard/
        dashboard.html
        dashboard.js
        dashboard.controller.js
        dashboard.service.js
      main/
  server/
      server.js
      api/
      data/
        data.tsv

我想使用儀表板控制器加載服務器的data.tsv 但是,它僅顯示404 Not Found

dashboard.controller.js

(function() {
    'use strict';
    angular
        .module('Dashboard')
        .controller('DashboardCtrl', DashboardCtrl);

    function DashboardCtrl($scope, d3) {
        d3.tsv("/data/data.tsv", function(data) {
            console.log(data[0])
        });
    }
})();

服務器

app.post('/data', function(req, res) {
    fs.readFile('./data/result.tsv', 'utf8', function(err, data) {
        if(err) {
            return console.log(err);
        }else {
            res.write(data);
            console.log('written!');
        }
    });
});

然后,如何在服務器中加載tsv文件?

請嘗試這個

fs.readFile("data/result.tsv", "utf8", function(error, data) { 
  data = d3.tsv.parse(data);
  console.log(JSON.stringify(data));
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM