0

I need to set the height and width of the svg file generated by JFreeChart. It is caused by I'm using svg to my html page (after all its pdf), and when I don't set any styles the image rendered in half.

DOMImplementation mySVGDOM= GenericDOMImplementation.getDOMImplementation();
/* create Document object */
Document document = mySVGDOM.createDocument(null, "svg", null);
document.createAttribute("width");
document.getDocumentElement().setAttribute("width", "1200px");
/* Create SVG Generator */
SVGGraphics2D my_svg_generator = new SVGGraphics2D(document);
/* Render chart as SVG 2D Graphics object */
chart.draw(my_svg_generator, new Rectangle2D.Double(0,0,1200,480));
/* Write output to file */

my_svg_generator.stream("output_pie_chart.svg");
return IOUtils.readUtf(new File("output_pie_chart.svg"));

The final result:

<svg width="1200px" height="1200px" fill-opacity="1" ...

This is currently:

<svg fill-opacity="1" ...

I would like to add width and height.

enter image description here

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
crosbee
  • 21
  • 5
  • Does this answer your question? [Create stylish charts in Java eg with JFreeChart](https://stackoverflow.com/questions/8264818/create-stylish-charts-in-java-eg-with-jfreechart) – Rob Audenaerde Feb 07 '23 at 08:56
  • No, I want to set the "svg" tag value, not the settings of the rendered svg file. – crosbee Feb 07 '23 at 09:02
  • If you are using [`jfreesvg`](https://github.com/jfree/jfreesvg), is there anything helpful in the demos cited there? – trashgod Feb 07 '23 at 12:20
  • I used CanvasSize in JFree and this solved the problem. Close. – crosbee Feb 08 '23 at 08:09
  • 2
    Glad you got it sorted; for reference, you can [answer your own question](http://meta.stackoverflow.com/q/17463/163188). – trashgod Feb 08 '23 at 23:07

0 Answers0