我生成报告时遇到问题,问题是图表重复
exp如果我在X轴上有5个元素,图表将重复5次
我的报告:
<?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);
}
答案 0 :(得分:1)
我认为这里的问题(你很可能已经发现,因为这个问题在7个月前被提出)是你已经将图表放入“详细信息”区域。您将为返回的每个元素(即查询中的数据行)重复详细信息区域。
您应将图表放入“标题”区域,或页面上其他“非重复”区域之一。