0

I think this has been asked before and I have found several references but still can't make it work so a little help please.

I was using Google Charts but for several reasons I have to switch so I have converted to d3 charts which for the most part have done everything I need but I still have one small problem. I need to generate a PDF files. I was using the getImageURI function from Google charts and passing that data to the server.

I tried the below code but the PDF generator says the image is invalid so I must be doing something wrong. Suggestions on how to fix it? I am using the latest version of d3, would prefer not to bounce off a outside server, and can't use anything from Google servers.

How can I simulate the getImageURI from Google Charts with d3?

Google code:

var img: any = chart.getImageURI();

d3 code:

function getChartImage(chartId: string): string {

var svg: any = d3.selectAll('svg').attr("version", 1.1).attr("xmlns", "http://www.w3.org/2000/svg");
var html: any = svg.node().parentNode.innerHTML
var img: string = "data:image/svg+xml;base64," + btoa(html);
return img;
}

var img: any = getChartImage("chart_div");
John Hughes
  • 367
  • 1
  • 3
  • 20
  • Another approach is to use canvas. See 'How to convert/save d3.js graph to pdf/jpeg [using canvas]' http://stackoverflow.com/questions/16049538/how-to-convert-save-d3-js-graph-to-pdf-jpeg/16050382. – widged Sep 06 '15 at 23:42
  • I have tried several solutions, so far none have worked. I have even exported to Adobe Ai. The chart is there and all the data is there but because I use css to format the formatting is lost, basically black blob. Anyway to move the css formatting to the SVG? – John Hughes Sep 11 '15 at 19:33
  • Ok fixed the Ai render problem, moved it all into the d3js code, no external css. Note the all browsers render the text correctly but Ai has a real problem with offsets but not going to try to fix it. – John Hughes Sep 11 '15 at 20:38

0 Answers0