4

I am visualizing some data with vaadin-charts:3.2.0, and I am trying to export a SVG out from the chart. I get some results but it is not satisfying. I can only share the screenshosts instead of the SVG itself. I also had to pixelate the labels to mask private data.

Original vaadin-charts seen on screen: Original vaadin-charts seen on screen

Exported SVG: Exported SVG

One problem is that the labels overflow the svg boundaries. And the chart drawings also overflow the boundaries making it seem like an incomplete drawing. Any idea what is wrong with this structure?

public class SvgStreamResource extends StreamResource {

  public SvgStreamResource(String svgText, String filename) {
    super(new StreamSource() {
      @Override
      public InputStream getStream() {
        InputStream s = new BufferedInputStream( new ReaderInputStream(new StringReader(svgText)));
        return s;
      }
    }, filename + ".svg");
  }

  @Override
  public String getMIMEType() {
    return "image/svg+xml";
  }

}

Within a component:

  Button exportButton = createExportButton("SVG", createSVGStreamSource(conf));
private SvgStreamResource createSVGStreamSource(Configuration conf) {
      String svg = SVGGenerator.getInstance().generate(conf);
      return new SvgStreamResource(svg, fileBaseName);
}
private Button createExportButton(String caption, SvgStreamResource svgStreamResource) {
      Button b = new Button(caption);
      FileDownloader downloader = new FileDownloader(svgStreamResource);
      downloader.extend(b);
      return b;
}
Sascha Frinken
  • 3,134
  • 1
  • 24
  • 27
ardarda
  • 63
  • 5
  • Not sure if it will make any difference, but could you try to create stream via `ByteArrayInputStream`? Something like this : `InputStream inputStream = new ByteArrayInputStream(svg.getBytes());` Or to disable tooltip to see, if it helps. There was problem with the generating images, when tooltip set, might be worth a try [Vaadin Charts - can't conver chart SVG to PNG](https://vaadin.com/forum/thread/14874253/vaadin-charts-can-t-conver-chart-svg-to-png) – anasmi May 01 '19 at 16:42
  • No, these don't help. – ardarda May 02 '19 at 03:52

0 Answers0