D3.js可视化与node.js [英] D3.js visualization with node.js
问题描述
我刚刚开始学习node.js,我想学习如何使用node创建一个D3.js视觉。任何人都可以解释我怎么可以这样做?理想情况下,我正在寻找一个尽可能简单的示例,我可以通过阅读代码并了解如何做到这一点。我看了一些长度,但我还没有找到任何可重复的例子。
I'm just starting to learn node.js and I'd like to learn how to use node to create a D3.js visual. Can anyone explain how I can go about doing this? Ideally, I'm looking for an example that is as simple as possible that I can read through the code and understand how to do this. I've looked at some length, but I haven't found any reproducible examples.
推荐答案
你想做什么? Node.js没有任何图形界面或DOM。
What are you trying to do? Node.js doesn't has any graphic interface or DOM.
您可以在节点中使用无头浏览器,但您仍然需要一个真正的浏览器来呈现结果。
You could use a headless browser in node but you would still require a real browser to render the results.
在注释后编辑:
如果您想要的是提供数据的节点应用程序,请尝试快速框架。
If what you want is a node app to serve data, try the express framework.
简单快速服务器:
var express = require('express');
var app = express();
app.get('/circle', function(req, res){
// CSP headers
res.set("Access-Control-Allow-Origin", "*");
res.set("Access-Control-Allow-Headers", "X-Requested-With");
// response
res.send({ x: 12, y: 34, r: 5 });
});
app.listen(3000);
使用Ajax请求获取值。您可能希望在响应中设置 CSP标头,以允许跨网域请求。
Use an Ajax request to get the values. Probably you want to set the CSP headers in the response to allow cross domain requests.
使用jQuery的客户:
$.get('http://yourserver.com:3000/circle', function(data) {
alert(data);
// set here your svg properties
});
这篇关于D3.js可视化与node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!