将D3.js与NodeJs和Express一起使用

时间:2014-03-29 18:59:17

标签: node.js express d3.js

我正在关注NodeJs和Express http://cwbuecheler.com/web/tutorials/2013/node-express-mongo/的本教程。

我需要使用D3显示条形图以进行数据可视化。我在app。的文件中做了一些更改:

var d3 = require('d3');
app.get('/d3', routes.d3);

将这些行添加到route / index.js:

exports.helloworld = function(req, res){
  res.render('d3');
};

在views目录中添加了一个新文件:d3.html包含来自此链接的index.html代码 http://bl.ocks.org/mbostock/3885304 并从同一链接添加了data.tsv。

我收到此错误:

/nodetest1/node_modules/express/lib/router/index.js:291
    throw new Error(msg);
          ^
Error: .get() requires callback functions but got a [object Undefined]
    at 
/nodetest1/node_modules/express/lib/router/index.js:291:11
    at Array.forEach (native)
    at Router.route 
(/nodetest1/node_modules/express/lib/router/index.js:287:13)
    at Router.(anonymous function) [as get] (/nodetest1/node_modules/express/lib/router/index.js:318:16)
    at Function.app.(anonymous function) [as get] (/nodetest1/node_modules/express/lib/application.js:412:26)
    at Object.<anonymous> (/nodetest1/app.js:38:5)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

1 个答案:

答案 0 :(得分:-2)

var d3 = require('d3');
app.get('/d3', d3.helloworld);
相关问题