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

Cannot display pie chart image in pdf file.


umme

Recommended Posts

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

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

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\reports

A 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

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:28



Post Edited by umme at 01/20/2010 06:34
Link to comment
Share on other sites

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.

regards

Umme.

Link to comment
Share on other sites

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...