0

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();
} 
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
littlemisschik
  • 139
  • 3
  • 9
  • "Java stops working" - what do you mean by that? Is there an exception being thrown or the JVM just silently kicks the bucket? – mszymborski Aug 15 '16 at 21:02
  • It silently kicks the bucket. – littlemisschik Aug 15 '16 at 21:03
  • Try `JDBCPieDataset`, mentioned [here](http://stackoverflow.com/a/16704682/230513).. – trashgod Aug 16 '16 at 01:27
  • @trashgod I tried that and I am still having the same problem. – littlemisschik Aug 16 '16 at 13:10
  • Please edit your question to include a [mcve] that shows what you tried; related, complete examples are cited [here](http://stackoverflow.com/a/28910878/230513); note that the required SQL is included; more [here](http://stackoverflow.com/search?tab=votes&q=%5bjfreechart%5d%20JDBCPieDataset). – trashgod Aug 16 '16 at 22:08

0 Answers0