score:5
Accepted answer
You may look this post. in these posts, some similar question has reached the answer.
D3js: how to generate standalone SVG files? (Nodejs)
Exporting D3.js graphs to static SVG files, programmatically
Hope these help and others come to answer.
score:8
I made an example in case that helps:
#!/usr/bin/env node
var d3 = require("d3"),
jsdom = require("jsdom");
const { JSDOM } = jsdom;
const { document } = (new JSDOM('')).window;
global.document = document;
var body = d3.select(document).select("body");
var width = 300;
var height = 300;
var svg = body.append("svg")
.attr("width", width)
.attr("height", height);
svg.append("line")
.attr("x1", 100)
.attr("y1", 100)
.attr("x2", 200)
.attr("y2", 200)
.style("stroke", "rgb(255,0,0)")
.style("stroke-width", 2);
const fs = require('fs');
fs.writeFileSync("test.svg", body.node().innerHTML)
Source: stackoverflow.com
Related Query
- How to use D3js on server side to generate SVG directly?
- Save d3js dynamically generated svg chart to png directly on server side
- d3js - Create a server side SVG with javascript actions
- How to generate part of html code on server side (nodejs)?
- How to use d3js force layout to generate the default hierarchical layout generated by graphviz dot
- how do I set up a grouping query on the server side. I want set up the query so I can use it for a pie chart in front end, using d3js
- How to use an arrow marker on an SVG <line> element?
- SVG to PNG Server side - using node.js
- D3js: how to generate standalone SVG files? (Nodejs)
- how to use svg file for image source in D3
- D3js : How to convert svg text to path?
- How to use SVG gradients to display varying colors relative to the size of the colored region
- How do I use D3js in Wordpress?
- How to map data such that I can use it to generate pie chart?
- How can I use a leaflet layer control to toggle a d3 svg overlay?
- How to assign click event to every svg element in d3js
- How to use D3 force layout with existing SVG elements as nodes
- How can I use SVG translate to center a d3.js projection to given latitude and longitude values?
- How to generate links towards right side in force layout D3.js
- Server Side d3 - Encoding SVG as a Base64 Image
- How to use d3.time.scale() to generate an array of evenly spaced dates?
- How to properly use the Use tag in SVG with d3 js?
- I am trying to use multiple 2 arrays for binding data for svg circles but cannot figure out how
- D3js SVG open lines display a fill artifact, how to fix it?
- How do I use d3.js to display text in an SVG rect only if the text will fit?
- Using D3 to generate SVG Pie Chart how to vertically align text
- How to make d3.js generate an svg without drawing it?
- How to add svg rectangles as background behind axis tick labels in d3js if ticks are inside chart
- d3js - How to use the `this` keyword or what is the alternate?
- How to create SVG with grid lines using D3JS
More Query from same tag
- d3.js: Handling multiple brushes
- Looping transition in D3 version 4 and 5
- Is there a way alter the color lines on D3.js line chart?
- update d3 pie chart with new data.json
- Formatting text from axis ticks in plotly using tickformat
- d3 contextmenu not firing
- responsive d3 area graph stretches circle interaction points
- .on ('mouseover') on d3
- Strange "initial" values in d3.js
- d3 autospace overlapping tick labels
- How do I make sure that data is passed correctly in d3 on drag?
- D3 Line and Path - graph line doesn't show
- Using Arc.Centroid to position a shape, but for some reason X & Y doesnt affect it
- Read inner and outer radius of arc - d3.js
- jQuery: Hiding a menu with click event
- What are the pros and cons for these approaches?
- Test mouseover and mouseout events in AngularJS directive
- Line chart in D3.js is not drawing properly
- Get SVG Element from Data Element?
- To remove minus sign from the values on the secondary Y-axis (Nvd3 -Multibar Horizontal Chart)
- d3.js force directed interactive coloring for groups
- Draw D3 Simple Line chart With an Array
- Changing size of rect to fit inside text
- d3 version 4 rescaleX where X scale is scaleTime
- How to rotate all text by x degree on x-axis in Javascript
- How to put the state name into the Geo chart/D3.js
- D3 Table Filter in R Shiny update SQL server
- d3 version 4, I'm trying to make a mouseover conditional based on class
- responsive axis values in d3
- Comparing mouse-overed element data to data in each element of the selection