I have a JFreeChart plot that I would like to save as a PNG file from a Java swing application.
XYPlot plot = (XYPlot)chart.getPlot();
plot.setBackgroundPaint(new Color(255,228,196));
ChartPanel panel = new ChartPanel(chart);
setContentPane(panel);
panel.setSize(600, 300);
JFileChooser exportChooser = new JFileChooser();
exportChooser.setSelectedFile(new File("test plot"));
FileFilter filter = new FileNameExtensionFilter("PNG File","png");
exportChooser.setFileFilter(filter);
int returnVal = exportChooser.showDialog(null, "Export");
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = exportChooser.getSelectedFile();
try {
OutputStream out = new FileOutputStream(file);
ChartUtilities.writeChartAsPNG(out, chart, panel.getWidth(), panel.getHeight());
}catch (IOException e) {
e.printStackTrace();
}catch (Throwable t){
t.printStackTrace();
}
}
I got this error:
java.lang.UnsatisfiedLinkError:
javax.imageio.ImageIO.write(Ljava/awt/image/RenderedImage;Ljava/lang/String;Ljava/io/OutputStream;)
I am not sure what this means or how to resolve it. I am also not sure if my code makes sense, specifically OutputStream out = new FileOutputStream(file);
. Would really appreciate any insights!