Using XChart I can make nice graphs. When I make the graph, I can right-click it, and an option to "save as" comes up. Then, I can save the image in a specified format, to a specified directory by clicking around.
How could I write Java code that automates this for me? That is, I have an application that creates about fifty graphs, and I don't want to have to deal with manually saving each one where it belongs every time I run the app.
Here's how I make my chart:
private void makeLineChart(int[][] data, String title) {
MyLineChart c = new MyLineChart(data, title);
XYChart chart = c.getChart();
new SwingWrapper<XYChart>(chart).displayChart();
// save as pdf...?
}
The sample code of xchart has the solution. BitmapEncoder can do that everytime you start your app.
BitmapEncoder.saveBitmap(chart, "./Sample_Chart", BitmapFormat.PNG);
} }