Example usage for org.jfree.graphics2d.svg SVGGraphics2D getSVGElement

List of usage examples for org.jfree.graphics2d.svg SVGGraphics2D getSVGElement

Introduction

In this page you can find the example usage for org.jfree.graphics2d.svg SVGGraphics2D getSVGElement.

Prototype

public String getSVGElement() 

Source Link

Document

Returns the SVG element that has been generated by calls to this Graphics2D implementation.

Usage

From source file:fr.amap.commons.javafx.chart.ChartViewer.java

/**
* A handler for the export to SVG option in the context menu.
*///from   w  ww .ja v  a 2  s .  com
private void handleExportToSVG() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export to SVG");
    fileChooser.setSelectedExtensionFilter(
            new FileChooser.ExtensionFilter("Scalable Vector Graphics (SVG)", "svg"));
    File file = fileChooser.showSaveDialog(stage);
    if (file != null) {

        CanvasPositionsAndSize canvasPositionAndSize = getCanvasPositionAndSize();

        SVGGraphics2D sVGGraphics2D = new SVGGraphics2D((int) canvasPositionAndSize.totalWidth,
                (int) canvasPositionAndSize.totalHeight);

        Graphics2D graphics2D = (Graphics2D) sVGGraphics2D.create();

        int index = 0;
        for (ChartCanvas canvas : chartCanvasList) {

            ((Drawable) canvas.chart).draw(graphics2D, canvasPositionAndSize.positionsAndSizes.get(index));
            index++;
        }

        try {
            SVGUtils.writeToSVG(file, sVGGraphics2D.getSVGElement());
        } catch (IOException ex) {
            Logger.getLogger(ChartViewer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}