有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java是否有使用JasperReports的气泡图资源?

我正在寻找Bubble Chart教程/JasperReports示例。我确实得到了预期的资源,示例程序jrxml模板。我已经在寻找在线和Jasper Ultimate Guide。我问这个问题的原因是把这个问题的答案保留在这里。不是其他的(例如:JavaFX图表),我必须使用JasperReports

任何机构帮助我提供以下数据(不是主题)简单的程序

资料

enter image description here

图表

enter image description here


共 (1) 个答案

  1. # 1 楼答案

    这里我得到了JasperReport{}示例的示例程序

    数据。爪哇

    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
    }
    

    泡泡试验。爪哇

    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