I am running a sql query and storing the results in a dataset. I am trying to put the results in a pie chart, but I only get the first row of results in the query to print and then Java stops working. I only get this error when I have this line of code in
ChartUtilities.saveChartAsJPEG(new File(filename), piechart, 500, 300);
I have inserted debug statements to make sure that I am storing all rows in the dataset. That works, and I can print them out to the screen; but when I try to save to the file, I get the error.
Here is my code.
String areatext = rs.getString("sum");
//System.out.println(areatext);
String depttext = rs.getString("dept");
System.out.println(depttext);
double area = Double.parseDouble(areatext);
System.out.println(area);
dataset.setValue(depttext, area);
System.out.println(dataset);
JFreeChart piechart = ChartFactory.createPieChart(
"test", // Title
dataset, // Dataset
true, // Show legend
true, // Use tooltips
false // Generate URLs
);
String filename = "c:piechart.jpg";
try {
ChartUtilities.saveChartAsJPEG(new File(filename), piechart, 500, 300);
} catch (IOException e) {
e.printStackTrace();
}