umme Posted January 14, 2010 Share Posted January 14, 2010 Hello,I'm building a simple report using ireport 3.7.0. I tried to set a pie chart using servlet in a pdf file. Also there is a simple tabular report part in detail tag. And the image in summary part.The report runs with the tabular part but blank shows in image part. But there is no error shown.The code is given below...EmployeeSevlet.java:public class EmployeeSevlet extends HttpServlet { Map<String, Object> params = new HashMap<String, Object>(); DBConnection dbConnection = new DBConnection(); private JasperDesign jasperDesign; 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) {.................................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(); data.setValue(employeeName, (Double)employeeData.get(employeeName)); } JFreeChart chart = ChartFactory.createPieChart("Employee Chart", data, true, true, true); return chart.createBufferedImage(500, 220); }.......................................................... Pls, help me with this. Link to comment Share on other sites More sharing options...
lucianc Posted January 15, 2010 Share Posted January 15, 2010 How does the <image> report element look like? Does the chart show in JasperViewer? How about in the server-side file (reportDestPDF)?Regards,Lucian Link to comment Share on other sites More sharing options...
umme Posted January 18, 2010 Author Share Posted January 18, 2010 Thanks for your reply.The Code for image report element in .jrxml's in summary portion is:------------------------------------------<summary> <band height="715"> <image scaleImage="RetainShape" hAlign="Center" vAlign="Middle" isUsingCache="false" evaluationTime="Page"> <reportElement key="element-41" mode="Opaque" x="0" y="33" width="514" height="252" forecolor="#000000" backcolor="#FFFFFF"> <property name="net.sf.jasperreports.export.pdf.tag.table" value="full"/> </reportElement> <graphicElement fill="Solid"> <pen lineWidth="1.0" lineStyle="Solid"/> </graphicElement> <imageExpression class="java.awt.Image"><![CDATA[$P{employeeChart}]]></imageExpression> </image> <staticText> <reportElement key="element-64" mode="Opaque" x="121" y="10" width="293" height="23" forecolor="#000000" backcolor="#FFFFFF"/> <textElement textAlignment="Center" verticalAlignment="Top" rotation="None" lineSpacing="Single"> <font fontName="Arial" size="18" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="true"/> </textElement> <text><![CDATA[Employee Chart]]></text> </staticText> </band> </summary>--------------------------------------------------------If I use to display piechart as [ChartFrame frame = new ChartFrame("EmployeeChart", chart); frame.pack(); frame.setVisible(true); ] then the piechart is displays individualy.Else it doesn't shows any reflaction.-----------------------------------------------------------------The report destination pdf file... path: D:\Drive D\netbeans\iReport\JasperReportSmartQ\reportsA pdf file created only with tabular part but there is no image. I herewith attached my employee.jrxml file.Please help me. Link to comment Share on other sites More sharing options...
lucianc Posted January 19, 2010 Share Posted January 19, 2010 Your code looks fine to me.Let me ask you again: Does the report chart show in JasperViewer? How about if you export to PDF from JasperViewer?Can you upload the resulting PDF file?Regards,Lucian Link to comment Share on other sites More sharing options...
umme Posted January 20, 2010 Author Share Posted January 20, 2010 Thanx again.NO, I can't see my chart in jasper viewer.The portion of where the pie chart to be shown is blank.I can upload that pdf file but the chartcontent is not there, only the tabular report part is containing there.I've test it only for pie chart not include the tabular part. And this time no pdf file has created showing no errors.If I use :[ ChartFrame frame = new ChartFrame("EmployeeChart", chart); frame.pack(); frame.setVisible(true); ]instead of createing image.. then I found my desired piechirt as output.pls help me. Post Edited by umme at 01/20/2010 06:28Post Edited by umme at 01/20/2010 06:34 Link to comment Share on other sites More sharing options...
lucianc Posted January 20, 2010 Share Posted January 20, 2010 I don't know how to help you, your code works fine for me.Post a self-contained test case for this so that I'd be able to reproduce the problem.Regards,Lucian Link to comment Share on other sites More sharing options...
umme Posted January 27, 2010 Author Share Posted January 27, 2010 Hey! Lucian,Thanx for your answer and cooperation. I've solved my problem. It was about ireport plugin for netbeans. After I reinstall my IDE and set ireport pluging environment again, I found my programs running without error including piechart.regardsUmme. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now