【问题标题】:generated jasper report is not showing bar chart生成的碧玉报告未显示条形图
【发布时间】:2012-02-01 13:42:01
【问题描述】:

我有一个具有代码的报表控制器:

@Controller
public class ReportsController {


@RequestMapping(value="report.htm",method=RequestMethod.GET)
        public String showReport() throws JRException{

                ... 
                InputStream reportStream = this.getClass().getResourceAsStream("/report.jrxml");                

                JRDataSource dataSource = new JRBeanCollectionDataSource(reportData);

                HashMap params = new HashMap();
                params.put("Title", "Report");

                JasperDesign jd = JRXmlLoader.load(reportStream);


                JasperReport jr = JasperCompileManager.compileReport(jd);

                JasperPrint jp = JasperFillManager.fillReport(jr, params, dataSource);

                JRHtmlExporter exporter = new JRHtmlExporter();

                exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);

                //EXPORTING REPORT TO A FILE "myreport.html"
                exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "E:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/mywebapp/WEB-INF/jsps/reports/reportsOutput/myreport.html"); //--------statement (1)

                exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, false);
                exporter.setParameter(JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, true);

                exporter.exportReport();

                return "report";
        }
}

在语句 (1) 中,我将生成的报告导出到文件 myreport.html

我的报告模板文件(report.jrxml)是:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report5" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <field name="count" class="java.lang.Integer"/>
    <field name="status" class="java.lang.String"/>
    <background>
        <band/>
    </background>
    <detail>
        <band height="343">
            <textField>
                <reportElement mode="Transparent" x="8" y="14" width="100" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.Integer"><![CDATA[$F{count}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Transparent" x="267" y="14" width="100" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{status}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement mode="Transparent" x="146" y="14" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[status]]></text>
            </staticText>
            <barChart>
                <chart>
                    <reportElement mode="Transparent" x="108" y="119" width="200" height="100"/>
                    <chartTitle/>
                    <chartSubtitle/>
                    <chartLegend/>
                </chart>
                <categoryDataset>
                    <categorySeries>
                        <seriesExpression><![CDATA[""]]></seriesExpression>
                        <categoryExpression><![CDATA[$F{status}]]></categoryExpression>
                        <valueExpression><![CDATA[$F{count}]]></valueExpression>
                        <itemHyperlink/>
                    </categorySeries>
                </categoryDataset>
                <barPlot>
                    <plot/>
                </barPlot>
            </barChart>
        </band>
    </detail>
</jasperReport>

问题是我在myreport.html 中生成的报告显示了所有内容但没有显示任何条形图,而是显示空白区域代替图表。 p>

有什么建议吗?

编辑:

图表数据由上述代码中的JasperPrint jp = JasperFillManager.fillReport(jr, params, dataSource);语句提供。

此外,还有一个由 jasper 报告 API 生成的文件夹,位于我的输出文件 (myreport.html) 所在的同一目录中:

/mywebapp/WEB-INF/jsps/reports/reportsOutput/myreport.html(输出文件)

/mywebapp/WEB-INF/jsps/reports/reportsOutput/myreport.html_files(生成的文件夹)

这个生成的文件夹 (myreport.html_files) 包含根据模板生成的图表图像并且是正确的但是这些图表图像没有显示在输出文件 myreport.html 以及其他文本输出中报告。 谢谢...

【问题讨论】:

  • 你认为是spring/web容器相关的问题吗? -- On 换句话说:你是否在(单元)测试中测试过?
  • @ralph:这不是弹簧相关的问题。该问题与exporting of jasper reports containing charts to a html file 有关。我将它标记为 spring,因为我在 spring 控制器中使用 jasper 报告。
  • 我刚刚检查了您的报表设计,发现您没有向图表组件提供任何数据。在世界上,图表将如何显示在报告中,而不提供任何数据?您需要设置“图表数据”并设置 Axis MinValue 和 MaxValue 表达式,以使其正常工作。
  • @bchetty:请看我的编辑。
  • @indyaah:在做了一些研发之后,我得出结论,要在 HTML 输出中显示图像,我们必须在 web.xml 中配置更多的东西,比如 IMAGE SERVLET(由 jasper 报告提供)和会话中的 JASPERPRINT 对象等。我正在尝试此解决方案,如果成功运行,将在此处打印解决方案。

标签: spring jasper-reports jfreechart


【解决方案1】:

如果有多种颜色的条,它们将显示为越来越弱的阴影。导出为 PDF,您可能会看到它们

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-14
    • 1970-01-01
    • 1970-01-01
    • 2013-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多