try
{
chartRemote = chartHome.create();
}catch(CreateException e){
logger.error("[execute] Exception thrown.", e);
throw new ServletException(e);
}
chartRemote.setDataSource(dataSource);
Collection chartRawData = (Collection)chartRemote.getTicketPieData(individualId, listParameters);
// Add the raw data to a JFree dataset
DefaultPieDataset pieData = new DefaultPieDataset();
int totalTickets = 0;
Iterator iter = chartRawData.iterator();
while (iter.hasNext())
{
HashMap row = (HashMap)iter.next();
String userName = (String)row.get("name");
Number openTickets = (Number)row.get("count");
if(userName == null){
userName = "UnAssigned";
}
totalTickets += openTickets.intValue();
pieData.setValue(userName, openTickets);
}
// create the chart
JFreeChart pieChart = ChartFactory.createPieChart("Open Tickets by User", pieData, true, true, false);
// add the "Total Open Tickets" sub-title
TextTitle t1 = new TextTitle("Total Open Tickets: " + String.valueOf(totalTickets),
new Font("SansSerif", Font.PLAIN, 11));
pieChart.addSubtitle(t1);
// set the chart visual options
PiePlot plot = (PiePlot)pieChart.getPlot();
plot.setForegroundAlpha(0.65f);
plot.setNoDataMessage("There are no currently open tickets.");
// print the chart image directly the the HTTP stream
OutputStream out = response.getOutputStream();
response.setContentType("image/jpeg");
try
{
ChartUtilities.writeChartAsJPEG(out, 1.0f, pieChart, 400, 300);
}catch(IOException e){
logger.error("[getOpportunityPieData] Exception thrown.", e);
throw new ServletException(e);
}finally{
out.close();
}
// return null (don't forward anywhere, we've done the output already)