2014-03-29 83 views
3

我正在关注NodeJs和Express http://cwbuecheler.com/web/tutorials/2013/node-express-mongo/上的本教程。与NodeJs和Express一起使用D3.js

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

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

增加这些线路路由/ index.js:

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

增加了一个新的文件目录的看法:从指数包含代码d3.html .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) 
+0

与app.get( '/ D3',routes.helloWorld)尝试; –

+0

我发现我的错误,在我的routes/index.js中有两个exports.helloworld。我修改了一个到exports.d3。该应用程序正在运行,但现在当我运行localhost:3000/d3它显示500错误:无法在视图目录“/ nodetest1/views”中查找视图“d3” – blackmamba

+0

我也得到了这个工作。必须使用ejs(HTML查看引擎)。但是html文件引用了views目录下的data.tsv文件,但我得到了404错误,因为它无法获取它。 – blackmamba

回答

-1
var d3 = require('d3'); 
app.get('/d3', d3.helloworld);