Java 生成「气泡图(浅蓝)」PDF 示例(Bubble)
Bubble2 页 A4 · 92 KB
以浅蓝气泡图呈现客户在余额、收益率与数量三个维度上的分布。

输出规格
- PDF 页数
- 2
- 图表类型
- Bubble
- 模板行数
- 193
- 源码行数
- 107
Java 源码 · JQuickCreditReport14BubbleTest.java
以下代码即生成上方 PDF 的完整测试类,可直接复制运行;Maven 依赖见快速开始章节。
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright (c) [2025-2099] Martin ([email protected])
*/
package com.github.paohaijiao.demo.creditreport;
import com.github.paohaijiao.JOption;
import com.github.paohaijiao.bubble.CategoryAxis;
import com.github.paohaijiao.bubble.ScatterSeries;
import com.github.paohaijiao.bubble.ValueAxis;
import com.github.paohaijiao.config.JPdfConfig;
import com.github.paohaijiao.demo.constant.JQuickConstant;
import com.github.paohaijiao.enums.JChartType;
import com.github.paohaijiao.executor.JQuickPdfFactory;
import com.github.paohaijiao.factory.JChartRendererFactory;
import org.junit.Test;
import java.awt.Color;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 统一信用报告 —— 风格 14:气泡图(浅蓝)
*
* <p>以 {@code report/credit_report_14_bubble.txt} 为模板,把气泡图渲染成 SVG 后
* 绑定到模板中的 {@code ${svg}} 占位符,输出到 {@code D:\test\creditreport\14_bubble.pdf}。</p>
*
* @author Martin
* @version 1.0.0
*/
public class JQuickCreditReport14BubbleTest {
public static final String path = JQuickConstant.path;
@Test
public void report14Bubble() throws IOException {
JOption option = new JOption();
option.title().text("风险气泡分布").subtext("气泡大小代表风险敞口,颜色代表风险等级");
option.legend("低风险", "中风险", "高风险");
option.xAxis(new CategoryAxis().name("账龄(月)"));
option.yAxis(new ValueAxis().name("逾期率(%)"));
ScatterSeries series = new ScatterSeries("风险敞口");
List<Map<String, Object>> seriesData = new ArrayList<>();
seriesData.add(bubblePoint("客户A", "3", 1.2, 120, "低风险"));
seriesData.add(bubblePoint("客户B", "6", 3.5, 260, "中风险"));
seriesData.add(bubblePoint("客户C", "9", 6.8, 410, "高风险"));
seriesData.add(bubblePoint("客户D", "4", 2.1, 180, "低风险"));
seriesData.add(bubblePoint("客户E", "12", 9.4, 560, "高风险"));
seriesData.add(bubblePoint("客户F", "8", 5.2, 330, "中风险"));
series.data(seriesData.toArray());
option.series(series);
String svg = JChartRendererFactory.renderChart(JChartType.Bubble, option);
File dir = new File(path + "creditreport");
if (!dir.exists()) {
dir.mkdirs();
}
FileOutputStream fileOutputStream = new FileOutputStream(path + "creditreport/14_bubble.pdf");
JPdfConfig config = new JPdfConfig();
// 开启 flex 行布局:图表与其右侧的指标说明面板在宽度允许时并排,而不是换行堆叠。
config.getLayoutConfig().setFlexLayout(true);
JQuickPdfFactory factory = new JQuickPdfFactory(config);
factory.bind("svg", svg);
byte[] bytes = factory.executeResource("report/credit_report_14_bubble.txt");
fileOutputStream.write(bytes);
fileOutputStream.close();
}
private static Map<String, Object> bubblePoint(String name, String x, double y, double size, String category) {
Map<String, Object> point = new HashMap<>();
point.put("x", x);
point.put("y", y);
point.put("size", size);
point.put("category", category);
point.put("name", name);
point.put("color", bubbleColor(category));
return point;
}
private static Color bubbleColor(String category) {
if ("低风险".equals(category)) {
return new Color(2, 136, 209, 180);
}
if ("中风险".equals(category)) {
return new Color(255, 167, 38, 180);
}
return new Color(229, 57, 53, 180);
}
}最小调用(3 行)
不想读完整测试类?核心就是这三行:绑定图表 SVG,执行模板,拿到 PDF 字节流。可直接复制到你的项目里。
// config 可省略;svg 来自 JChartRendererFactory.renderChart(...),见下方完整源码
factory.bind("svg", svg);
byte[] pdf = new JQuickPdfFactory(config).executeResource("report/credit_report_14_bubble.txt");模板文件 · 14_bubble.txt
类 HTML + 内联 CSS 的模板语法,绑定数据后渲染为 PDF。下方为完整模板,可直接复制,也可下载原始文件。
<pdf>
<body>
<div style="background:linear-gradient(135deg, #01579B 0%, #03A9F4 100%); borderRadius:8px; padding:18px; marginBottom:12px">
<h1 style="textAlignment:center; color:white; fontSize:21; bold:true; marginBottom:8px">'企业信用评级报告'</h1>
<p style="textAlignment:center; color:#e1f5fe; fontSize:10; margin:2px">'报告编号: CR-2023-08975 | 评估日期: 2023年11月15日'</p>
<p style="textAlignment:center; color:#e1f5fe; fontSize:10; margin:2px">'评估机构: 四川省企业信用评估中心'</p>
</div>
<div style="marginBottom:14px">
<table style="width:600px; fontSize:10">
<tr>
<th style="width:150px; padding:6px; backgroundColor:#0288D1; color:white; textAlignment:center">'企业名称'</th>
<th style="padding:6px; backgroundColor:#0288D1; color:white; textAlignment:left">'四川省泡海椒科技有限公司'</th>
</tr>
<tr>
<td style="width:150px; padding:6px; backgroundColor:#e1f5fe; bold:true">'统一信用代码'</td>
<td style="padding:6px">'91110108MA01XX1234'</td>
</tr>
<tr>
<td style="padding:6px; backgroundColor:#e1f5fe; bold:true">'成立日期'</td>
<td style="padding:6px">'2018年5月20日'</td>
</tr>
<tr>
<td style="padding:6px; backgroundColor:#e1f5fe; bold:true">'注册资本'</td>
<td style="padding:6px">'1000万元人民币'</td>
</tr>
<tr>
<td style="padding:6px; backgroundColor:#e1f5fe; bold:true">'法定代表人'</td>
<td style="padding:6px">'泡海椒'</td>
</tr>
<tr>
<td style="padding:6px; backgroundColor:#e1f5fe; bold:true">'所属行业'</td>
<td style="padding:6px">'软件和信息技术服务业'</td>
</tr>
<tr>
<td style="padding:6px; backgroundColor:#e1f5fe; bold:true">'企业规模'</td>
<td style="padding:6px">'中型(150-200人)'</td>
</tr>
</table>
</div>
<div style="marginBottom:14px">
<h2 style="color:#01579B; fontSize:13; bold:true; marginBottom:10px">'历年财务数据(单位:万元)'</h2>
<table style="width:600px; fontSize:10">
<tr>
<th style="backgroundColor:#0288D1; color:white; padding:6px; textAlignment:center">'财务指标'</th>
<th style="backgroundColor:#0288D1; color:white; padding:6px; textAlignment:center">'2020年'</th>
<th style="backgroundColor:#0288D1; color:white; padding:6px; textAlignment:center">'2021年'</th>
<th style="backgroundColor:#0288D1; color:white; padding:6px; textAlignment:center">'2022年'</th>
<th style="backgroundColor:#0288D1; color:white; padding:6px; textAlignment:center">'2023年'</th>
<th style="backgroundColor:#0288D1; color:white; padding:6px; textAlignment:center">'增长率'</th>
</tr>
<tr>
<td style="padding:5px; bold:true; borderBottom:1px solid #b3e5fc">'营业收入'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #b3e5fc">'8,560'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #b3e5fc">'12,340'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #b3e5fc">'18,920'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #b3e5fc">'25,680'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #b3e5fc; color:#2e7d32; bold:true">'+44.2%'</td>
</tr>
<tr>
<td style="padding:5px; bold:true; backgroundColor:#f2fafd; borderBottom:1px solid #b3e5fc">'净利润'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f2fafd; borderBottom:1px solid #b3e5fc">'1,240'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f2fafd; borderBottom:1px solid #b3e5fc">'2,150'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f2fafd; borderBottom:1px solid #b3e5fc">'3,890'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f2fafd; borderBottom:1px solid #b3e5fc">'5,420'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f2fafd; borderBottom:1px solid #b3e5fc; color:#2e7d32; bold:true">'+63.8%'</td>
</tr>
<tr>
<td style="padding:5px; bold:true; borderBottom:1px solid #b3e5fc">'总资产'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #b3e5fc">'15,800'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #b3e5fc">'22,450'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #b3e5fc">'31,200'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #b3e5fc">'42,800'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #b3e5fc; color:#2e7d32; bold:true">'+39.5%'</td>
</tr>
<tr>
<td style="padding:5px; bold:true; backgroundColor:#f2fafd; borderBottom:1px solid #b3e5fc">'净资产'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f2fafd; borderBottom:1px solid #b3e5fc">'9,200'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f2fafd; borderBottom:1px solid #b3e5fc">'13,800'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f2fafd; borderBottom:1px solid #b3e5fc">'19,500'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f2fafd; borderBottom:1px solid #b3e5fc">'26,400'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f2fafd; borderBottom:1px solid #b3e5fc; color:#2e7d32; bold:true">'+42.1%'</td>
</tr>
<tr>
<td style="padding:5px; bold:true; borderBottom:1px solid #b3e5fc">'毛利率'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #b3e5fc">'42.5%'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #b3e5fc">'45.8%'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #b3e5fc">'48.2%'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #b3e5fc">'51.6%'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #b3e5fc; color:#2e7d32; bold:true">'+9.1%'</td>
</tr>
</table>
</div>
<div style="marginBottom:14px">
<h2 style="color:#01579B; fontSize:13; bold:true; marginBottom:10px">'关键经营指标'</h2>
<div style="display:flex; marginBottom:9px">
<div style="width:22px; paddingTop:3px">
<div style="width:10px; height:10px; borderRadius:5px; backgroundColor:#03A9F4"></div>
</div>
<div style="width:560px; fontSize:11">
<span style="bold:true; color:#01579B">'营收增长率: '</span>
'连续三年保持40%以上增长,2023年达到25,680万元'
</div>
</div>
<div style="display:flex; marginBottom:9px">
<div style="width:22px; paddingTop:3px">
<div style="width:10px; height:10px; borderRadius:5px; backgroundColor:#03A9F4"></div>
</div>
<div style="width:560px; fontSize:11">
<span style="bold:true; color:#01579B">'利润率提升: '</span>
'净利率从14.5%提升至21.1%,盈利能力显著增强'
</div>
</div>
<div style="display:flex; marginBottom:9px">
<div style="width:22px; paddingTop:3px">
<div style="width:10px; height:10px; borderRadius:5px; backgroundColor:#03A9F4"></div>
</div>
<div style="width:560px; fontSize:11">
<span style="bold:true; color:#01579B">'研发投入: '</span>
'研发费用年均增长38.9%,占营收比例达13.3%'
</div>
</div>
<div style="display:flex; marginBottom:9px">
<div style="width:22px; paddingTop:3px">
<div style="width:10px; height:10px; borderRadius:5px; backgroundColor:#03A9F4"></div>
</div>
<div style="width:560px; fontSize:11">
<span style="bold:true; color:#01579B">'人才结构: '</span>
'技术研发人员占比42%,硕士以上学历占35%'
</div>
</div>
<div style="display:flex; marginBottom:9px">
<div style="width:22px; paddingTop:3px">
<div style="width:10px; height:10px; borderRadius:5px; backgroundColor:#03A9F4"></div>
</div>
<div style="width:560px; fontSize:11">
<span style="bold:true; color:#01579B">'客户质量: '</span>
'服务15家上市公司,客户续约率92%,大客户满意度4.8/5.0'
</div>
</div>
<div style="display:flex; marginBottom:9px">
<div style="width:22px; paddingTop:3px">
<div style="width:10px; height:10px; borderRadius:5px; backgroundColor:#03A9F4"></div>
</div>
<div style="width:560px; fontSize:11">
<span style="bold:true; color:#01579B">'资产质量: '</span>
'资产负债率维持在38%左右,流动比率2.8,偿债能力良好'
</div>
</div>
</div>
<div style="marginBottom:14px">
<h2 style="color:#01579B; fontSize:13; bold:true; marginBottom:10px">'风险气泡分布图'</h2>
<div style="display:flex; justifyContent:space-between">
<svg style="width:390px;height:400px">${svg}</svg>
<div style="width:300px; backgroundColor:#e1f5fe; borderRadius:6px; padding:12px">
<h3 style="color:#01579B; fontSize:12; bold:true; marginBottom:8px">'评级指标说明'</h3>
<div style="fontSize:10; marginBottom:6px">
<span style="bold:true; color:#0288D1">'财务状况(90分): '</span>
'营收稳定增长'
</div>
<div style="fontSize:10; marginBottom:6px">
<span style="bold:true; color:#0288D1">'经营能力(95分): '</span>
'客户留存率高'
</div>
<div style="fontSize:10; marginBottom:6px">
<span style="bold:true; color:#0288D1">'偿债能力(85分): '</span>
'负债率合理'
</div>
<div style="fontSize:10; marginBottom:6px">
<span style="bold:true; color:#0288D1">'发展潜力(92分): '</span>
'研发投入增加'
</div>
</div>
</div>
</div>
<div style="marginBottom:14px; backgroundColor:#e1f5fe; borderRadius:8px; padding:16px; borderLeft:4px solid #0288D1">
<h2 style="color:#01579B; fontSize:13; bold:true; marginBottom:8px">'综合评价'</h2>
<p style="textAlignment:justify; fontSize:11">
'四川省泡海椒科技有限公司作为国家级高新技术企业和专精特新"小巨人"企业,在云计算和大数据领域表现出色。公司财务状况健康,经营能力突出,技术创新能力强,具备良好的发展潜力。信用评级为AAA级,展望稳定。'
</p>
</div>
<div style="textAlignment:center; marginTop:12px">
<p style="fontSize:9; color:#4fc3f7">'本报告依据公开信息和专业评估模型生成,仅供参考 | 报告生成时间: 2025年09月06日'</p>
<p style="fontSize:9; color:#4fc3f7">'© 2023 企业信用评估中心 版权所有 | 认证编号: CE-2023-001'</p>
</div>
</body>
</pdf>同分组示例
本页 PDF、预览图、模板与源码均由 JQuick-Pdf 真实运行产出,可自由复制到你的项目中使用。