List of usage examples for org.jfree.graphics2d.svg SVGUtils writeToSVG
public static void writeToSVG(File file, String svgElement) throws IOException
From source file:org.jfree.graphics2d.demo.SVGBarChartDemo1.java
/** * Starting point for the demo./* w w w .j a va 2 s. c o m*/ * * @param args ignored. * * @throws IOException */ public static void main(String[] args) throws IOException { JFreeChart chart = createChart(createDataset()); SVGGraphics2D g2 = new SVGGraphics2D(600, 400); Rectangle r = new Rectangle(0, 0, 600, 400); chart.draw(g2, r); File f = new File("SVGBarChartDemo1.svg"); SVGUtils.writeToSVG(f, g2.getSVGElement()); }
From source file:org.jfree.graphics2d.demo.ImageTest.java
/** * Starting point for the demo.//from www . j a v a 2 s .c o m * * @param args ignored. * * @throws IOException */ public static void main(String[] args) throws IOException { // BufferedImage image = new BufferedImage(200, 200, // BufferedImage.TYPE_INT_ARGB); // Graphics2D g2 = image.createGraphics(); SVGGraphics2D g2 = new SVGGraphics2D(110, 110); //drawClipTest(g2); //drawGradientPaintTest(g2); drawLinearGradientPaintTest(g2); //drawOldLinearGradientPaintTest(g2); //drawRadialGradientPaintTest(g2); //drawArcTest(g2); // ImageIO.write(image, "png", new File("oldlgp-test.png")); SVGUtils.writeToSVG(new File("lgp-test.svg"), g2.getSVGElement()); }
From source file:org.jfree.graphics2d.demo.SVGPieChartDemo1.java
/** * Starting point for the demo./*from w w w . j a v a 2s . co m*/ * * @param args ignored. * * @throws IOException */ public static void main(String[] args) throws IOException { JFreeChart chart = createChart(createDataset()); SVGGraphics2D g2 = new SVGGraphics2D(600, 400); g2.setRenderingHint(JFreeChart.KEY_SUPPRESS_SHADOW_GENERATION, true); Rectangle r = new Rectangle(0, 0, 600, 400); chart.draw(g2, r); File f = new File("SVGPieChartDemo1.svg"); SVGUtils.writeToSVG(f, g2.getSVGElement()); }
From source file:org.jfree.graphics2d.demo.SVGChartWithAnnotationsDemo1.java
/** * Starting point for the demo./*from w w w . j ava 2s . com*/ * * @param args ignored. * * @throws IOException */ public static void main(String[] args) throws IOException { JFreeChart chart = createChart(createDataset()); SVGGraphics2D g2 = new SVGGraphics2D(500, 300); Rectangle r = new Rectangle(0, 0, 500, 300); chart.draw(g2, r); File f = new File("SVGChartWithAnnotationsDemo1.svg"); SVGUtils.writeToSVG(f, g2.getSVGElement()); }
From source file:org.jfree.graphics2d.demo.SwingUIToSVGDemo.java
@Override public void actionPerformed(ActionEvent e) { JComponent c = (JComponent) getContentPane().getComponent(0); SVGGraphics2D g2 = new SVGGraphics2D(c.getWidth(), c.getHeight()); c.paint(g2);/*from w w w . j a v a2 s .c om*/ File f = new File("SwingUIToSVGDemo.svg"); try { SVGUtils.writeToSVG(f, g2.getSVGElement()); } catch (IOException ex) { System.err.println(ex); } }
From source file:gavisualizer.LineChart.java
@Override public void saveAsSVG(String path, int width, int height) throws IOException { // Save image as SVG SVGGraphics2D g2 = new SVGGraphics2D(width, height); Rectangle r = new Rectangle(0, 0, width, height); _chart.draw(g2, r);/* ww w .ja v a 2 s . com*/ File f = new File(path); SVGUtils.writeToSVG(f, g2.getSVGElement()); }
From source file:org.jfree.graphics2d.demo.SVGTimeSeriesChartDemo1.java
/** * Starting point for the demo./*from w w w . ja v a 2 s . co m*/ * * @param args ignored. * * @throws IOException */ public static void main(String[] args) throws IOException { JFreeChart chart = createChart(createDataset()); SVGGraphics2D g2 = new SVGGraphics2D(600, 400); g2.setRenderingHint(JFreeChart.KEY_SUPPRESS_SHADOW_GENERATION, true); Rectangle r = new Rectangle(0, 0, 600, 400); chart.draw(g2, r); File f = new File("SVGTimeSeriesChartDemo1.svg"); SVGUtils.writeToSVG(f, g2.getSVGElement()); }
From source file:fr.amap.commons.javafx.chart.ChartViewer.java
/** * A handler for the export to SVG option in the context menu. *//*from w w w .ja va2 s .c om*/ 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); } } }
From source file:keel.Algorithms.UnsupervisedLearning.AssociationRules.Visualization.keelassotiationrulesboxplot.ResultsProccessor.java
public void writeToFile(String outName) throws FileNotFoundException, UnsupportedEncodingException, IOException { //calcMeans(); // Create JFreeChart Dataset DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); HashMap<String, ArrayList<Double>> measuresFirst = algorithmMeasures.entrySet().iterator().next() .getValue();/*from w w w.j a v a 2 s. co m*/ for (Map.Entry<String, ArrayList<Double>> measure : measuresFirst.entrySet()) { String measureName = measure.getKey(); //Double measureValue = measure.getValue(); dataset.clear(); for (Map.Entry<String, HashMap<String, ArrayList<Double>>> entry : algorithmMeasures.entrySet()) { String alg = entry.getKey(); ArrayList<Double> measureValues = entry.getValue().get(measureName); // Parse algorithm name to show it correctly String aName = alg.substring(0, alg.length() - 1); int startAlgName = aName.lastIndexOf("/"); aName = aName.substring(startAlgName + 1); dataset.add(measureValues, aName, measureName); } // Tutorial: http://www.java2s.com/Code/Java/Chart/JFreeChartBoxAndWhiskerDemo.htm final CategoryAxis xAxis = new CategoryAxis("Algorithm"); final NumberAxis yAxis = new NumberAxis("Value"); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); // Black and White int numItems = algorithmMeasures.size(); for (int i = 0; i < numItems; i++) { Color color = Color.DARK_GRAY; if (i % 2 == 1) { color = Color.LIGHT_GRAY; } renderer.setSeriesPaint(i, color); renderer.setSeriesOutlinePaint(i, Color.BLACK); } renderer.setMeanVisible(false); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("SansSerif", Font.BOLD, 10); //ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jchart = new JFreeChart("Assotiation Rules Measures - BoxPlot", font, plot, true); //StandardChartTheme.createLegacyTheme().apply(jchart); int width = 640 * 2; /* Width of the image */ int height = 480 * 2; /* Height of the image */ // JPEG File chart = new File(outName + "_" + measureName + "_boxplot.jpg"); ChartUtilities.saveChartAsJPEG(chart, jchart, width, height); // SVG SVGGraphics2D g2 = new SVGGraphics2D(width, height); Rectangle r = new Rectangle(0, 0, width, height); jchart.draw(g2, r); File BarChartSVG = new File(outName + "_" + measureName + "_boxplot.svg"); SVGUtils.writeToSVG(BarChartSVG, g2.getSVGElement()); } }
From source file:keel.Algorithms.UnsupervisedLearning.AssociationRules.Visualization.keelassotiationrulesbarchart.ResultsProccessor.java
public void writeToFile(String outName) throws FileNotFoundException, UnsupportedEncodingException, IOException { calcMeans();/*from ww w .j av a 2s .c o m*/ calcAvgRulesBySeed(); // Create JFreeChart Dataset DefaultCategoryDataset dataset = new DefaultCategoryDataset(); HashMap<String, Double> measuresFirst = algorithmMeasures.entrySet().iterator().next().getValue(); for (Map.Entry<String, Double> measure : measuresFirst.entrySet()) { String measureName = measure.getKey(); //Double measureValue = measure.getValue(); dataset.clear(); for (Map.Entry<String, HashMap<String, Double>> entry : algorithmMeasures.entrySet()) { String alg = entry.getKey(); Double measureValue = entry.getValue().get(measureName); // Parse algorithm name to show it correctly String aName = alg.substring(0, alg.length() - 1); int startAlgName = aName.lastIndexOf("/"); aName = aName.substring(startAlgName + 1); dataset.addValue(measureValue, aName, measureName); ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart barChart = ChartFactory.createBarChart("Assotiation Rules Measures", measureName, measureName, dataset, PlotOrientation.VERTICAL, true, true, false); StandardChartTheme.createLegacyTheme().apply(barChart); CategoryItemRenderer renderer = barChart.getCategoryPlot().getRenderer(); // Black and White int numItems = algorithmMeasures.size(); for (int i = 0; i < numItems; i++) { Color color = Color.DARK_GRAY; if (i % 2 == 1) { color = Color.LIGHT_GRAY; } renderer.setSeriesPaint(i, color); renderer.setSeriesOutlinePaint(i, Color.BLACK); } int width = 640 * 2; /* Width of the image */ int height = 480 * 2; /* Height of the image */ // JPEG File BarChart = new File(outName + "_" + measureName + "_barchart.jpg"); ChartUtilities.saveChartAsJPEG(BarChart, barChart, width, height); // SVG SVGGraphics2D g2 = new SVGGraphics2D(width, height); Rectangle r = new Rectangle(0, 0, width, height); barChart.draw(g2, r); File BarChartSVG = new File(outName + "_" + measureName + "_barchart.svg"); SVGUtils.writeToSVG(BarChartSVG, g2.getSVGElement()); } } /* for (Map.Entry<String, HashMap<String, Double>> entry : algorithmMeasures.entrySet()) { String alg = entry.getKey(); HashMap<String, Double> measures = entry.getValue(); for (Map.Entry<String, Double> entry1 : measures.entrySet()) { String measureName = entry1.getKey(); Double measureValue = entry1.getValue(); dataset.addValue(measureValue, alg, measureName); } } */ }