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
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. 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.
精彩评论