简体   繁体   English

使用 JasperReport 绘制图表的问题

[英]Problem with charting using JasperReport

I have a problem when I generate a report,the problem is that chart repeats生成报告时出现问题,问题是图表重复

exp if I have in the X axis 5 elements,the chart will be repeated 5 times exp 如果我在 X 轴上有 5 个元素,图表将重复 5 次

My report:我的报告:

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

My code:我的代码:

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);


         }

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.我认为这里的问题(你很可能已经发现了这个问题,因为这个问题是 7 个月前提出的)是你把图表放到了“细节”区域。 You will have the detail area repeated for each element returned (ie 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.您应该将图表放入“标题”区域,或页面上的其他“非重复”区域之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM