gpt4 book ai didi

java - 有使用 JasperReports 绘制气泡图的资源吗?

转载 作者:太空宇宙 更新时间:2023-11-04 14:32:11 27 4
gpt4 key购买 nike

我正在寻找气泡图教程/JasperReports示例。我确实得到了我期望的资源,示例程序jrxml模板。我已经在网上寻找Jasper Ultimate Guide。我为什么问这个问题,是为了把这个问题的答案保留在这里。不是其他(例如:JavaFX Chart),我必须使用JasperReports

任何人帮助我提供简单的程序,如下数据(不是主题)。

数据

enter image description here

图表

enter image description here

最佳答案

这里我得到了 JasperReport Bubble Chart 示例的示例程序。

数据.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
}

BubbleChartTest.java

public class BubbleChartTest {
public static void main(String[] args) throws Exception {
List<Data> dataList = new ArrayList<Data>();
dataList.add(new Data("A", 1d, 3d, 0.3));
dataList.add(new Data("A", 2d, 3d, 0.2));
dataList.add(new Data("B", 5d, 6d, 0.4));
dataList.add(new Data("B", 4d, 3d, 0.2));
dataList.add(new Data("B", 2d, 5d, 0.1));
dataList.add(new Data("C", 5d, 6d, 0.2));
dataList.add(new Data("C", 2d, 3d, 0.3));
dataList.add(new Data("C", 4d, 5d, 0.4));
String templateFile = "resources/bubble.jrxml";
JasperDesign design = JRXmlLoader.load(templateFile);
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");
}
}

气泡.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="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" theme="aegean">
<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>

输出

enter image description here

关于java - 有使用 JasperReports 绘制气泡图的资源吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26009136/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com