使用JasperReport绘制图表的问题

使用JasperReport绘制图表的问题

本文介绍了使用JasperReport绘制图表的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成报告时遇到问题,问题是图表重复

I have a problem when I generate a report,the problem is that chart repeats

exp如果我在X轴上有5个元素,图表将重复5次

exp if I have in the X axis 5 elements ,the chart will be repeated 5 times

我的报告:

<?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="BarChartproject" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<parameter name="SQL" class="java.lang.String">
    <defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<queryString>
    <![CDATA[$P!{SQL}]]>
</queryString>
<field name="nb" class="java.lang.Long"/>
<field name="priority" class="java.lang.String"/>
<field name="project" class="java.lang.String"/>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="79" splitType="Stretch"/>
</title>
<pageHeader>
    <band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
    <band height="18" splitType="Stretch"/>
</columnHeader>
<detail>
    <band height="178" splitType="Stretch">
        <stackedBar3DChart>
            <chart>
                <reportElement x="70" y="21" width="363" height="132"/>
                <chartTitle/>
                <chartSubtitle/>
                <chartLegend/>
            </chart>
            <categoryDataset>
                <categorySeries>
                    <seriesExpression><![CDATA[$F{project}]]></seriesExpression>
                    <categoryExpression><![CDATA[$F{project}]]></categoryExpression>
                    <valueExpression><![CDATA[$F{nb}]]></valueExpression>
                </categorySeries>
            </categoryDataset>
            <bar3DPlot>
                <plot/>
                <itemLabel color="#000000" backgroundColor="#FFFFFF"/>
                <categoryAxisFormat>
                    <axisFormat>
                        <labelFont/>
                        <tickLabelFont/>
                    </axisFormat>
                </categoryAxisFormat>
                <valueAxisFormat>
                    <axisFormat>
                        <labelFont/>
                        <tickLabelFont/>
                    </axisFormat>
                </valueAxisFormat>
            </bar3DPlot>
        </stackedBar3DChart>
    </band>
</detail>
<columnFooter>
    <band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
    <band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
    <band height="42" splitType="Stretch"/>
</summary>

我的代码:

public String ConstructSQL()
{
 System.out.println("status------"+this.getMyChoiceStatus());
 System.out.println("chartssssssssss------"+this.getChartType());
 for(int i=0;i<checkbox.length;i++)
 {
    if (checkbox[i].equals("1"))
    {
        System.out.println("priority checked");
        select ="select count(jiraissue.id) as nb ,jiraissue.priority,jiraissue.project,jiraissue.issuestatus";
        from =" from jiraissue,issuestatus";
        where =" where issuestatus.id=jiraissue.issuestatus";
         and =" and issuestatus.pname ="+"'"+this.getMyChoiceStatus()+"'";
        groupBy=" group by jiraissue.priority";
        sql =select+from+where+and+groupBy+" ;";
         System.out.println("SQL report------"+this.sql);

        return sql;

        }
       else
    {

    if (checkbox[i].equals("2"))
    {
        System.out.println("project checked");
        select ="select count(jiraissue.id) as nb ,jiraissue.project,jiraissue.priority,jiraissue.issuestatus";
        from =" from jiraissue,issuestatus";
        where =" where issuestatus.id=jiraissue.issuestatus";
         and =" and issuestatus.pname ="+"'"+this.getMyChoiceStatus()+"'";
        groupBy=" group by jiraissue.project";
        sql =select+from+where+and+groupBy+" ;";

         System.out.println("SQL report------"+this.sql);

       return sql;

    }
    }

 }
 return sql;
}


public void fillReport()
{

try {
            // - Connexion à la base

            Driver monDriver = new com.mysql.jdbc.Driver();
            DriverManager.registerDriver(monDriver);
            connection = (Connection)  DriverManager.getConnection("jdbc:mysql://localhost:3306/jiradb", "","");

            // - Chargement et compilation du rapport
           JasperDesign jasperDesign = JRXmlLoader.load("C:/Documents and Settings/My Documents/NetBeansProjects/JiraMap/src/java/Reports/"+chartType+chartGrouping()+".jrxml");
            JasperReport jasperReport =   JasperCompileManager.compileReport(jasperDesign);
Map parameterMap = new HashMap();
parameterMap.put("SQL",ConstructSQL());

           // // - Execution du rapport
           JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,parameterMap, connection);

            // - Création du rapport au format PDF
           JasperExportManager.exportReportToPdfFile(jasperPrint, "C:/Documents and Settings/My Documents/NetBeansProjects/JiraMap/src/java/Reports/"+chartType+chartGrouping()+".pdf");
              // JasperViewer.viewReport(jasperPrint);


         }


推荐答案

我认为这里的问题(你很可能已经发现这个问题已经在7个月前被解决)是你已经把图表放到了'细节'区域。您将为返回的每个元素重复详细信息区域(即查询中的数据行)。

I think the issue here (which you have most probably discovered already as this question was aksed 7 months ago) is that you have placed the chart into the 'Detail' area. You will have the detail area repeated for each element returned (i.e. row of data in a query).

您应该将图表放入标题区域,或者一个页面上其他非重复区域。

You should place the chart into the 'Title' area, or one of the other 'non-repeating' areas on a page.

这篇关于使用JasperReport绘制图表的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:14