Jump to content
We've recently updated our Privacy Statement, available here ×

iReports-3.7.0/piechart Cannot show on web.


umme

Recommended Posts

Hello all,

I'm new in ireport and try to make my first report to display piechart using servlet.

I'm using netbeans 6.1 and ireport 3.7.0. I can display a simple tabular report but can't a piechart as pdf output.

There is not any warnings or errors to catch my implementation problems. Pls. help me with this....

Code:
EmployeeServlet.java:protected void processRequest(HttpServletRequest request, HttpServletResponse response)    throws ServletException, IOException {        response.setContentType("text/html;charset=UTF-8");        EmployeeReport employeeReport = new EmployeeReport();        try {            String servletPath = getServletContext().getRealPath("/");            String reportSource =servletPath +  "template/employee.jrxml";                       String reportDestPDF =servletPath +  "reports/EmployeeReport.pdf";                     params.put("reportTitle", "Hello Report World");            params.put("author", "Umme Habiba");            params.put("startDate", (new java.util.Date()).toString());            params.put("employeeChart", employeeReport.createEmployeeChartImage());                                  jasperDesign = JRXmlLoader.load(reportSource);            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);                       Connection conn;                        conn = dbConnection.getConnection();                                JasperPrint jasperPrint =JasperFillManager.fillReport(jasperReport, params, conn);                         JasperExportManager.exportReportToPdfFile(jasperPrint, reportDestPDF);		               ServletOutputStream servletOutputStream = response.getOutputStream();                       JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);                       JasperViewer.viewReport(jasperPrint);            response.setContentType("application/pdf");            servletOutputStream.flush();            servletOutputStream.close();                            } catch (JRException ex) {                     Logger.getLogger(EmployeeSevlet.class.getName()).log(Level.SEVERE, null, ex);                    }     } ------------------------------createEmployeeChartImage():------------------------------public java.awt.Image createEmployeeChartImage(){        java.util.Hashtable employeeData = getEmployeeData();              DefaultPieDataset data = new DefaultPieDataset();              for(java.util.Enumeration e = employeeData.keys(); e.hasMoreElements();){            String employeeName = (String)e.nextElement();            System.out.println("dataset key element... " + employeeName);            data.setValue(employeeName, (Double)employeeData.get(employeeName));        }                JFreeChart chart = ChartFactory.createPieChart("Employee Chart", data, true, true, true);                     return chart.createBufferedImage(500, 220);    }
Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...