try
{
chartRemote = chartHome.create();
}catch(CreateException e){
logger.error("[execute] Exception thrown.", e);
throw new ServletException(e);
}
chartRemote.setDataSource(dataSource);
Collection chartRawData = (Collection)chartRemote.getTicketBarData(individualId, listParameters);
// Add the raw data to a JFree dataset
DefaultCategoryDataset chartData = new DefaultCategoryDataset();
Iterator iter = chartRawData.iterator();
while (iter.hasNext())
{
HashMap row = (HashMap)iter.next();
Number openTickets = (Number)row.get("count");
String userName = (String)row.get("name");
if(userName == null){
userName = "UnAssigned";
}
Number ageValue = (Number)row.get("age");
chartData.setValue(openTickets, userName, this.getAgeName(ageValue));
}
// create the chart
JFreeChart barChart = ChartFactory.createStackedBarChart("Open Tickets by Age", "Age", "# Open Tickets",
chartData, org.jfree.chart.plot.PlotOrientation.VERTICAL,
true, true, false);
// set the visual options
CategoryPlot plot = barChart.getCategoryPlot();
// set the X axis labels to be slanted
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 3.0));
// set the range axis to display integers only...
final NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// set the max width of each bar
BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setMaxBarWidth(0.10);
// print the chart image directly the the HTTP stream
OutputStream out = response.getOutputStream();
response.setContentType("image/jpeg");
try
{
ChartUtilities.writeChartAsJPEG(out, 1.0f, barChart, 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)