使用D3.js与NodeJs和Express [英] Using D3.js with NodeJs and Express

查看:869
本文介绍了使用D3.js与NodeJs和Express的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在NodeJs和Express上遵循本教程 http:// cwbuecheler。 com / web / tutorials / 2013 / node-express-mongo /



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

  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);
^
错误:.get()需要回调函数,但得到一个[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路由器(匿名函数)[as get](/nodetest1/node_modules/express/lib/router/index.js:318:16)
在Function.app。(匿名函数)[as get](/ nodetest1 /node_modules/express/lib/application.js:412:26)
at Object。< anonymous> (/nodetest1/app.js:38:5)
在Module._compile(module.js:456:26)
在Object.Module._extensions..js(module.js:474:10 )
at Module.load(module.js:356:32)
at Function.Module._load(module.js:312:12)
pre>

解决方案

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


I am following this tutorial on NodeJs and Express http://cwbuecheler.com/web/tutorials/2013/node-express-mongo/.

I need to display bar charts using D3 for data visualisation. I made some changes in app.'s file :

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

Added these lines to route/index.js:

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

Added a new file to views directory: d3.html containing code from index.html from this link http://bl.ocks.org/mbostock/3885304 and added data.tsv from same link.

I get this error:

/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)

解决方案

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

这篇关于使用D3.js与NodeJs和Express的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆