現在、JavaアプリケーションからJasperReportsのレポートを生成するために、Jaspersoft Studio 6.3.0とjasperreports-6.2.0.jarを使用しています。JasperReportsの1つのチャートで複数のXY線が表示される
JRBeanCollectionDataSourceを使用して複数のxy線グラフ(1行だけではない)を作成する必要があります。
1行だけのデータを含む単一のxyデータリストList<Coordinates>
を使用すると、正しいXY線グラフが1行だけ表示されます。 しかし、私は複数の線がグラフ上にプロットされている必要があります。そして、描画される線の数は動的です。
私はJRubeanCollectionDataSourceで複数のxy線図を検索しようとしましたが、それらはすべてデータベースクエリを使用して同じ例を持っています。
ジャスパーのための良い読書資料を誰かが提案することができます。これは私のために始まったばかりなので、後で私はジャスパー報告書を使って文書を生成しなければならないと思います。ジャスパー(チャート、テーブル、静的データ、目次など)。
Beanクラス:私はそれに複数行のデータを保持できるように、私は
List<List<Coordinates>> coordinatesList = new ArrayList<>();
を作成しました :
public class Coordinates {
public Coordinates(Number xCoordinate, Number yCoordinate) {
super();
this.xCoordinate = xCoordinate;
this.yCoordinate = yCoordinate;
}
public Coordinates() {
}
private Number xCoordinate;
private Number yCoordinate;
public Number getxCoordinate() {
return xCoordinate;
}
public void setxCoordinate(Number xCoordinate) {
this.xCoordinate = xCoordinate;
}
public Number getyCoordinate() {
return yCoordinate;
}
public void setyCoordinate(Number yCoordinate) {
this.yCoordinate = yCoordinate;
}
これは私がレポートを作成する方法です。ここで
JRBeanCollectionDataSource coordiantesListBean = new JRBeanCollectionDataSource(coordinatesList);
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream projectInputStream = classloader.getResourceAsStream("jasper/xyLineChart.jasper");
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("XYChartDataSource", coordiantesListBean);
try {
JasperPrint jasperPrint = JasperFillManager.fillReport(projectInputStream, parameters,
new JREmptyDataSource());
JasperExportManager.exportReportToPdfFile(jasperPrint,FILE_LOCATION);
} catch (JRException e) {
e.printStackTrace();
}
実際には、複数の行は、JasperReportsの中に複数の系列を意味し、私のxyLineChart.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="test" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f5d035d9-630a-476c-b3d1-32985d774cb3">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<subDataset name="XYdataset" uuid="276f43e3-9d6c-4df1-85cb-5ea8bef1c28c">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="XYChartDataSource" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource">
<parameterDescription><![CDATA[]]></parameterDescription>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<field name="xCoordinate" class="java.lang.Number"/>
<field name="yCoordinate" class="java.lang.Number"/>
</subDataset>
<parameter name="XYChartDataSource" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<queryString>
<![CDATA[]]>
</queryString>
<summary>
<band height="283" splitType="Stretch">
<xyLineChart>
<chart evaluationTime="Report">
<reportElement x="0" y="0" width="555" height="283" uuid="9c9ff114-81b4-433f-bf71-17e21ea1fd3e"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<xyDataset>
<dataset>
<datasetRun subDataset="XYdataset" uuid="a8b4a706-dfaf-4347-9410-3c7018fce5f2">
<dataSourceExpression><![CDATA[$P{XYChartDataSource}]]></dataSourceExpression>
</datasetRun>
</dataset>
<xySeries autoSort="true">
<seriesExpression><![CDATA["SERIES 1"]]></seriesExpression>
<xValueExpression><![CDATA[$F{xCoordinate}]]></xValueExpression>
<yValueExpression><![CDATA[$F{yCoordinate}]]></yValueExpression>
</xySeries>
</xyDataset>
<linePlot>
<plot/>
<categoryAxisFormat>
<axisFormat/>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat/>
</valueAxisFormat>
</linePlot>
</xyLineChart>
</band>
</summary>
</jasperReport>