我的JAVA项目需要使用图表生成PDF,如下所示。我设法得到了贾斯珀报告的类似图表。但是,尽管Jasper报告,我无法实现以下目标。
这就是我得到的:
请求您的建议通过Jasper报告或此图表可用的任何其他合适的Java工具来实现上述项目。
JReport的:
public class JReport {
public static void main(String[] args) throws Exception {
List<Data> dataList = new ArrayList<Data>();
dataList.add(new Data("A", 1, 3d, 0.3));
dataList.add(new Data("A", 2d, 4d, 0.3));
dataList.add(new Data("A", 2d, 3d, 0.3));
dataList.add(new Data("B", 2d, 4d, 0.3));
dataList.add(new Data("A", 2d, 3d, 0.4));
dataList.add(new Data("B", 5d, 6d, 0.4));
dataList.add(new Data("B", 4d, 3d, 0.3));
dataList.add(new Data("B", 2d, 5d, 0.3));
dataList.add(new Data("C", 5d, 6d, 0.3));
dataList.add(new Data("C", 2d, 3d, 0.3));
dataList.add(new Data("C", 4d, 5d, 0.4));
String templateFile = "C:\\WS\\bubble.jrxml";
File file = new File(templateFile);
JasperDesign design = JRXmlLoader.load(file);
JasperReport report = JasperCompileManager.compileReport(design);
Map parameter = new HashMap();
JasperPrint print = JasperFillManager.fillReport(report, parameter, new JRBeanCollectionDataSource(dataList));
JasperExportManager.exportReportToPdfFile(print, "D:/temp/bubble_chart.pdf");
}
}
Data.java
public class Data {
private String name;
private double x;
private double y;
private double z;
public Data(String name, double x, double y, double z) {
this.name = name;
this.x = x;
this.y = y;
this.z = z;
}
// getter, setter
Bubble.jrxml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="BubbleChartReport" columnCount="2" pageWidth="595" pageHeight="842" columnWidth="270" columnSpacing="15" leftMargin="20" rightMargin="20" topMargin="30">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<field name="name" class="java.lang.String"/>
<field name="x" class="java.lang.Double"/>
<field name="y" class="java.lang.Double"/>
<field name="z" class="java.lang.Double"/>
<pageHeader>
<band height="203">
<bubbleChart>
<chart evaluationTime="Report" >
<reportElement positionType="Float" x="0" y="2" width="555" height="197"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<xyzDataset>
<xyzSeries>
<seriesExpression><![CDATA[$F{name}]]></seriesExpression>
<xValueExpression><![CDATA[$F{x}]]></xValueExpression>
<yValueExpression><![CDATA[$F{y}]]></yValueExpression>
<zValueExpression><![CDATA[$F{z}]]></zValueExpression>
</xyzSeries>
</xyzDataset>
<bubblePlot scaleType="RangeAxis">
<plot/>
<xAxisFormat>
<axisFormat/>
</xAxisFormat>
<yAxisFormat>
<axisFormat/>
</yAxisFormat>
</bubblePlot>
</bubbleChart>
</band>
</pageHeader>
</jasperReport>