在Node.js中使用Rickshaw / D3,对于服务器端,原始svg可访问?

我正在尝试在Node中使用D3和Rickshaw。 该服务必须创build一个时间序列图,然后使用运行imagemagick的subprocess将原始SVG转换为png。 我真的只需要一个原始的svgstring来做我的转换。 人力车有没有办法访问一个原始的SVGstring?

人力车内部使用d3 ,你可以像在真正的DOM中一样获得SVGstring:

 var Rickshaw = require('rickshaw'), jsdom = require('jsdom'); jsdom.env({ features: { QuerySelector: true }, html: '<html><body><div id="graph"></div></body></html>', done: function (err, window) { this.window = window; this.document = window.document; // classListShim(window.self); // <-- see comment below var graph = new Rickshaw.Graph({ series: [ { data: [ { x: 0, y: 2 }, { x: 1, y: 4 }] } ], renderer: 'area', element: window.document.querySelector('#graph') }); graph.render(); // This will output the `svg` element in HTML format. console.log(window.document.querySelector('#graph').innerHTML); } }); 

但是,因为currely jsdom不支持classList ,所以需要使用window.self上应用的classList shim 。

完整的代码: https : //gist.github.com/musically-ut/9154438