Open amergin opened 10 years ago
Although this is really a general browser problem (and there is a lot of discussion on the d3 mailing list about different methods), it would be nice to have a built-in feature for it, or at least a pointer to a method or library on the FAQ.
Here is a demonstration of one technique: http://d3export.housegordon.org/
Related: #671 export as image (png)
Here's a fairly comprehensive SO answer. (I haven't tried it yet.)
My problems are related to styling of the SVG elements produced by dc.js. Whenever I get an svg file out, it's crearly missing the custom css styles in dc.css
, even when supplied external stylings with CDATA
. The most impressive implementation I've seen is http://nytimes.github.io/svg-crowbar/.
EDIT: seems they've released a new version, SVG crowbar 2, which seems to style DC.js figures properly - I need to take a look at the implementation.
Now revisiting this problem, the issue is not anymore about how to get the serialized svg string out embedded with the relevant css rules; Svg-crowbar2 functions are wonderful for that.
The new problem: the output svg file renders differently in browsers and viewers like Inkscape. Consider this example file from the dc.js, with proper headers the file can be viewed here.
Chrome: axes visible, main content hidden Firefox: axes and main content visible Safari: axes and main content visible Inkscape: axes and main content visible.
I'm thinking the file contains some piece of inline css that is interpreted differently on these viewers. For instance I remember reading that Inkscape does not have very sophisticated SVG support for some pieces of the newer standard.
Any ideas?
Asked this same question in Stack overflow and got an explanation.
As the height
and width
styles are set on export by Crowbar, it seems to be a bug on their part.
I would be interested to know any tips or current solutions on how to reliably export DC.js charts regardless of the chart type. My own stabs at exporting have more or less failed: after exporting the svg with inline css applied, the result looks very much different than the original chart.