/** * Save a Chart as an image file * * @param chart * @param fileName * @param bitmapFormat * @throws IOException */ public static void saveBitmap(Chart chart, String fileName, BitmapFormat bitmapFormat) throws IOException { OutputStream out = new FileOutputStream(addFileExtension(fileName, bitmapFormat)); try { saveBitmap(chart, out, bitmapFormat); } finally { out.close(); } }
public static void main(String[] args) throws IOException { double[] xData = new double[] {0.0, 1.0, 2.0}; double[] yData = new double[] {2.0, 1.0, 0.0}; // Create Chart XYChart chart = QuickChart.getChart("Sample Chart", "X", "Y", "y(x)", xData, yData); // Show it new SwingWrapper<XYChart>(chart).displayChart(); // Save it BitmapEncoder.saveBitmap(chart, "./Sample_Chart", BitmapFormat.PNG); // or save it in high-res BitmapEncoder.saveBitmapWithDPI(chart, "./Sample_Chart_300_DPI", BitmapFormat.PNG, 300); } }
/** * Save list of Charts as an image file. Function assumes that all charts are the same size * (width, height). Number of charts should equal rows multiplied by cols. * * @param charts * @param rows number of rows * @param cols number of columns * @param fileName * @param bitmapFormat * @throws IOException */ public static void saveBitmap( List<Chart> charts, Integer rows, Integer cols, String fileName, BitmapEncoder.BitmapFormat bitmapFormat) throws IOException { OutputStream out = new FileOutputStream(addFileExtension(fileName, bitmapFormat)); try { saveBitmap(charts, rows, cols, out, bitmapFormat); } finally { out.close(); } }
public static void main(String[] args) throws Exception { double[] yData = new double[] {2.0, 1.0, 0.0}; // Create Chart XYChart chart = new XYChart(500, 400); chart.setTitle("Sample Chart"); chart.setXAxisTitle("X"); chart.setXAxisTitle("Y"); XYSeries series = chart.addSeries("y(x)", null, yData); series.setMarker(SeriesMarkers.CIRCLE); BitmapEncoder.saveBitmap(chart, "./Sample_Chart", BitmapFormat.PNG); BitmapEncoder.saveBitmap(chart, "./Sample_Chart", BitmapFormat.JPG); BitmapEncoder.saveJPGWithQuality(chart, "./Sample_Chart_With_Quality.jpg", 0.95f); BitmapEncoder.saveBitmap(chart, "./Sample_Chart", BitmapFormat.BMP); BitmapEncoder.saveBitmap(chart, "./Sample_Chart", BitmapFormat.GIF); BitmapEncoder.saveBitmapWithDPI(chart, "./Sample_Chart_300_DPI", BitmapFormat.PNG, 300); BitmapEncoder.saveBitmapWithDPI(chart, "./Sample_Chart_300_DPI", BitmapFormat.JPG, 300); BitmapEncoder.saveBitmapWithDPI(chart, "./Sample_Chart_300_DPI", BitmapFormat.GIF, 300); VectorGraphicsEncoder.saveVectorGraphic(chart, "./Sample_Chart", VectorGraphicsFormat.EPS); VectorGraphicsEncoder.saveVectorGraphic(chart, "./Sample_Chart", VectorGraphicsFormat.PDF); VectorGraphicsEncoder.saveVectorGraphic(chart, "./Sample_Chart", VectorGraphicsFormat.SVG); } }
public static void main(String[] args) throws Exception { List<Chart> charts = Arrays.asList( new Chart[] { createChart("chart1", new double[] {2.0, 1.0, 0.0}), createChart("chart2", new double[] {3.0, 4.0, 0.0}), createChart("chart3", new double[] {4.0, 1.5, 0.0}), createChart("chart4", new double[] {2.0, 3.0, 0.0}), createChart("chart5", new double[] {4.0, 1.0, 0.0}), createChart("chart6", new double[] {5.0, 2.0, 0.0}) }); BitmapEncoder.saveBitmap(charts, 2, 3, "./Sample_Charts", BitmapFormat.PNG); }
try { if (fileChooser.getFileFilter() == null) { BitmapEncoder.saveBitmap(chart, theFileToSave.getCanonicalPath(), BitmapFormat.PNG); } else if (fileChooser.getFileFilter().getDescription().equals("*.jpg,*.JPG")) { BitmapEncoder.saveJPGWithQuality( 1.0f); } else if (fileChooser.getFileFilter().getDescription().equals("*.png,*.PNG")) { BitmapEncoder.saveBitmap(chart, theFileToSave.getCanonicalPath(), BitmapFormat.PNG); } else if (fileChooser.getFileFilter().getDescription().equals("*.bmp,*.BMP")) { BitmapEncoder.saveBitmap(chart, theFileToSave.getCanonicalPath(), BitmapFormat.BMP); } else if (fileChooser.getFileFilter().getDescription().equals("*.gif,*.GIF")) { BitmapEncoder.saveBitmap(chart, theFileToSave.getCanonicalPath(), BitmapFormat.GIF); } else if (fileChooser.getFileFilter().getDescription().equals("*.svg,*.SVG")) { VectorGraphicsEncoder.saveVectorGraphic(
public static void main(String[] args) throws IOException { int numCharts = 4; List<Chart> charts = new ArrayList<Chart>(); for (int i = 0; i < numCharts; i++) { XYChart chart = new XYChartBuilder().xAxisTitle("X").yAxisTitle("Y").width(600).height(400).build(); chart.getStyler().setYAxisMin(-10.0); chart.getStyler().setYAxisMax(10.0); XYSeries series = chart.addSeries("" + i, null, getRandomWalk(200)); series.setMarker(SeriesMarkers.NONE); charts.add(chart); } new SwingWrapper<Chart>(charts).displayChartMatrix(); BitmapEncoder.saveBitmap(charts, 2, 2, "./Sample_Chart_Matrix", BitmapEncoder.BitmapFormat.PNG); }
public void saveChart(String fileName, BitmapFormat format) throws IOException { for (String chart : this.charts.keySet()) { BitmapEncoder.saveBitmap(this.charts.get(chart), fileName + "_" + chart, format); } }
public void saveChart(String fileName, BitmapFormat format) throws IOException { for (String chart : this.charts.keySet()) { BitmapEncoder.saveBitmap(this.charts.get(chart), fileName + "_" + chart, format); } }
/** * Save a Chart as an image file * * @param chart * @param fileName * @param bitmapFormat * @throws IOException */ public static void saveBitmap(Chart chart, String fileName, BitmapFormat bitmapFormat) throws IOException { OutputStream out = new FileOutputStream(addFileExtension(fileName, bitmapFormat)); try { saveBitmap(chart, out, bitmapFormat); } finally { out.close(); } }
/** * Save list of Charts as an image file. Function assumes that all charts are the same size * (width, height). Number of charts should equal rows multiplied by cols. * * @param charts * @param rows number of rows * @param cols number of columns * @param fileName * @param bitmapFormat * @throws IOException */ public static void saveBitmap( List<Chart> charts, Integer rows, Integer cols, String fileName, BitmapEncoder.BitmapFormat bitmapFormat) throws IOException { OutputStream out = new FileOutputStream(addFileExtension(fileName, bitmapFormat)); try { saveBitmap(charts, rows, cols, out, bitmapFormat); } finally { out.close(); } }
public void actionPerformed(ActionEvent e) { try{ FileDialog fd = new FileDialog(dialog, "Save as PNG", FileDialog.SAVE); fd.setFile("evaluation.png"); fd.setVisible(true); String name = fd.getDirectory() + fd.getFile(); File file = new File(name); BitmapEncoder.saveBitmap(chart, file.getCanonicalPath(), BitmapFormat.PNG); } catch(Exception ex) { ex.printStackTrace(); } } });
try { if (fileChooser.getFileFilter() == null) { BitmapEncoder.saveBitmap(chart, theFileToSave.getCanonicalPath(), BitmapFormat.PNG); } else if (fileChooser.getFileFilter().getDescription().equals("*.jpg,*.JPG")) { BitmapEncoder.saveJPGWithQuality( 1.0f); } else if (fileChooser.getFileFilter().getDescription().equals("*.png,*.PNG")) { BitmapEncoder.saveBitmap(chart, theFileToSave.getCanonicalPath(), BitmapFormat.PNG); } else if (fileChooser.getFileFilter().getDescription().equals("*.bmp,*.BMP")) { BitmapEncoder.saveBitmap(chart, theFileToSave.getCanonicalPath(), BitmapFormat.BMP); } else if (fileChooser.getFileFilter().getDescription().equals("*.gif,*.GIF")) { BitmapEncoder.saveBitmap(chart, theFileToSave.getCanonicalPath(), BitmapFormat.GIF); } else if (fileChooser.getFileFilter().getDescription().equals("*.svg,*.SVG")) { VectorGraphicsEncoder.saveVectorGraphic(
try { File f = new File("./Sample_Chart.png"); BitmapEncoder.saveBitmap(chart, f.getAbsolutePath(), BitmapEncoder.BitmapFormat.PNG); bot.queue.add(channel.sendFile(f), message -> f.delete()); } catch (IOException e) {