Treemap (blue grey) — generate this PDF with Java (TREEMAP)
TREEMAP2 页 A4 · 75 KB
Shows the relative size of each business segment as a blue grey treemap.

Output specs
- PDF pages
- 2
- Chart type
- TREEMAP
- Template lines
- 170
- Source lines
- 87
Java source · JQuickCreditReport13TreemapTest.java
This is the complete test class that produced the PDF above — copy it and run as-is; see the quick-start section for the Maven dependency.
/*
* 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.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 com.github.paohaijiao.treemap.JTreeMapNode;
import com.github.paohaijiao.treemap.TreeMapOption;
import org.junit.Test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* 统一信用报告 —— 风格 13:矩形树图(蓝灰)
*
* <p>以 {@code report/credit_report_13_treemap.txt} 为模板,把矩形树图渲染成 SVG 后
* 绑定到模板中的 {@code ${svg}} 占位符,输出到 {@code D:\test\creditreport\13_treemap.pdf}。</p>
*
* @author Martin
* @version 1.0.0
*/
public class JQuickCreditReport13TreemapTest {
public static final String path = JQuickConstant.path;
@Test
public void report13Treemap() throws IOException {
JTreeMapNode root = new JTreeMapNode("业务总览", 1000);
JTreeMapNode product = new JTreeMapNode("软件产品", 400);
JTreeMapNode service = new JTreeMapNode("技术服务", 250);
JTreeMapNode cloud = new JTreeMapNode("云服务", 200);
JTreeMapNode other = new JTreeMapNode("其他业务", 150);
product.addChild(new JTreeMapNode("企业管理软件", 240));
product.addChild(new JTreeMapNode("行业解决方案", 160));
service.addChild(new JTreeMapNode("实施服务", 130));
service.addChild(new JTreeMapNode("运维服务", 120));
cloud.addChild(new JTreeMapNode("公有云", 140));
cloud.addChild(new JTreeMapNode("私有云", 60));
other.addChild(new JTreeMapNode("培训", 80));
other.addChild(new JTreeMapNode("硬件", 70));
root.addChild(product);
root.addChild(service);
root.addChild(cloud);
root.addChild(other);
TreeMapOption treemapOption = new TreeMapOption();
treemapOption.setRoot(root);
JOption option = new JOption();
option.setTreemapOption(treemapOption);
option.title("业务板块矩形树图");
String svg = JChartRendererFactory.renderChart(JChartType.TREEMAP, option);
File dir = new File(path + "creditreport");
if (!dir.exists()) {
dir.mkdirs();
}
FileOutputStream fileOutputStream = new FileOutputStream(path + "creditreport/13_treemap.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_13_treemap.txt");
fileOutputStream.write(bytes);
fileOutputStream.close();
}
}Minimal invocation (3 lines)
Skip the full test class — the core is these three lines: bind the chart SVG, execute the template, get the PDF bytes. Copy them straight into your project.
// config 可省略;svg 来自 JChartRendererFactory.renderChart(...),见下方完整源码
factory.bind("svg", svg);
byte[] pdf = new JQuickPdfFactory(config).executeResource("report/credit_report_13_treemap.txt");Template file · 13_treemap.txt
An HTML-like template with inline CSS that renders to PDF once bound to data. The full template is below — copy it or download the raw file.
<pdf>
<body>
<div style="backgroundColor:#37474F; padding:14px; marginBottom:6px">
<div style="display:flex; justifyContent:space-between; alignItems:center">
<h1 style="color:white; fontSize:20; bold:true">'企业信用评级报告'</h1>
<div style="width:260px; textAlignment:right">
<p style="color:#cfd8dc; fontSize:9; textAlignment:right; margin:1px">'报告编号: CR-2023-08975'</p>
<p style="color:#cfd8dc; fontSize:9; textAlignment:right; margin:1px">'评估日期: 2023年11月15日'</p>
</div>
</div>
</div>
<p style="color:#607d8b; fontSize:10; marginBottom:14px">'评估机构: 四川省企业信用评估中心'</p>
<div style="marginBottom:14px">
<h2 style="color:#37474F; fontSize:14; bold:true; marginBottom:8px">'四川省泡海椒科技有限公司'</h2>
<table style="width:600px; fontSize:10">
<tr>
<td style="width:160px; padding:6px; backgroundColor:#eceff1; bold:true; borderBottom:1px solid #cfd8dc">'统一信用代码'</td>
<td style="padding:6px; borderBottom:1px solid #cfd8dc">'91110108MA01XX1234'</td>
</tr>
<tr>
<td style="padding:6px; backgroundColor:#eceff1; bold:true; borderBottom:1px solid #cfd8dc">'成立日期'</td>
<td style="padding:6px; borderBottom:1px solid #cfd8dc">'2018年5月20日'</td>
</tr>
<tr>
<td style="padding:6px; backgroundColor:#eceff1; bold:true; borderBottom:1px solid #cfd8dc">'注册资本'</td>
<td style="padding:6px; borderBottom:1px solid #cfd8dc">'1000万元人民币'</td>
</tr>
<tr>
<td style="padding:6px; backgroundColor:#eceff1; bold:true; borderBottom:1px solid #cfd8dc">'法定代表人'</td>
<td style="padding:6px; borderBottom:1px solid #cfd8dc">'泡海椒'</td>
</tr>
<tr>
<td style="padding:6px; backgroundColor:#eceff1; bold:true; borderBottom:1px solid #cfd8dc">'所属行业'</td>
<td style="padding:6px; borderBottom:1px solid #cfd8dc">'软件和信息技术服务业'</td>
</tr>
<tr>
<td style="padding:6px; backgroundColor:#eceff1; bold:true; borderBottom:1px solid #cfd8dc">'企业规模'</td>
<td style="padding:6px; borderBottom:1px solid #cfd8dc">'中型(150-200人)'</td>
</tr>
</table>
</div>
<div style="marginBottom:14px">
<h2 style="color:#546E7A; fontSize:13; bold:true; marginBottom:10px">'历年财务数据(单位:万元)'</h2>
<table style="width:600px; fontSize:10">
<tr>
<th style="backgroundColor:#546E7A; color:white; padding:6px; textAlignment:center">'财务指标'</th>
<th style="backgroundColor:#546E7A; color:white; padding:6px; textAlignment:center">'2020年'</th>
<th style="backgroundColor:#546E7A; color:white; padding:6px; textAlignment:center">'2021年'</th>
<th style="backgroundColor:#546E7A; color:white; padding:6px; textAlignment:center">'2022年'</th>
<th style="backgroundColor:#546E7A; color:white; padding:6px; textAlignment:center">'2023年'</th>
<th style="backgroundColor:#546E7A; color:white; padding:6px; textAlignment:center">'增长率'</th>
</tr>
<tr>
<td style="padding:5px; bold:true; borderBottom:1px solid #cfd8dc">'营业收入'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #cfd8dc">'8,560'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #cfd8dc">'12,340'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #cfd8dc">'18,920'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #cfd8dc">'25,680'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #cfd8dc; color:#2e7d32; bold:true">'+44.2%'</td>
</tr>
<tr>
<td style="padding:5px; bold:true; backgroundColor:#f4f6f7; borderBottom:1px solid #cfd8dc">'净利润'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f4f6f7; borderBottom:1px solid #cfd8dc">'1,240'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f4f6f7; borderBottom:1px solid #cfd8dc">'2,150'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f4f6f7; borderBottom:1px solid #cfd8dc">'3,890'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f4f6f7; borderBottom:1px solid #cfd8dc">'5,420'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f4f6f7; borderBottom:1px solid #cfd8dc; color:#2e7d32; bold:true">'+63.8%'</td>
</tr>
<tr>
<td style="padding:5px; bold:true; borderBottom:1px solid #cfd8dc">'总资产'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #cfd8dc">'15,800'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #cfd8dc">'22,450'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #cfd8dc">'31,200'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #cfd8dc">'42,800'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #cfd8dc; color:#2e7d32; bold:true">'+39.5%'</td>
</tr>
<tr>
<td style="padding:5px; bold:true; backgroundColor:#f4f6f7; borderBottom:1px solid #cfd8dc">'净资产'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f4f6f7; borderBottom:1px solid #cfd8dc">'9,200'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f4f6f7; borderBottom:1px solid #cfd8dc">'13,800'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f4f6f7; borderBottom:1px solid #cfd8dc">'19,500'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f4f6f7; borderBottom:1px solid #cfd8dc">'26,400'</td>
<td style="padding:5px; textAlignment:right; backgroundColor:#f4f6f7; borderBottom:1px solid #cfd8dc; color:#2e7d32; bold:true">'+42.1%'</td>
</tr>
<tr>
<td style="padding:5px; bold:true; borderBottom:1px solid #cfd8dc">'毛利率'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #cfd8dc">'42.5%'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #cfd8dc">'45.8%'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #cfd8dc">'48.2%'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #cfd8dc">'51.6%'</td>
<td style="padding:5px; textAlignment:right; borderBottom:1px solid #cfd8dc; color:#2e7d32; bold:true">'+9.1%'</td>
</tr>
</table>
</div>
<div style="marginBottom:14px">
<h2 style="color:#546E7A; fontSize:13; bold:true; marginBottom:10px">'关键经营指标'</h2>
<div style="display:flex; flexWrap:wrap">
<div style="width:290px; margin:4px; padding:10px; backgroundColor:#eceff1; borderRadius:4px; borderLeft:3px solid #78909C">
<p style="bold:true; color:#37474F; fontSize:11; marginBottom:4px">'营收增长率'</p>
<p style="fontSize:10; color:#455a64">'连续三年保持40%以上增长,2023年达到25,680万元'</p>
</div>
<div style="width:290px; margin:4px; padding:10px; backgroundColor:#eceff1; borderRadius:4px; borderLeft:3px solid #78909C">
<p style="bold:true; color:#37474F; fontSize:11; marginBottom:4px">'利润率提升'</p>
<p style="fontSize:10; color:#455a64">'净利率从14.5%提升至21.1%,盈利能力显著增强'</p>
</div>
<div style="width:290px; margin:4px; padding:10px; backgroundColor:#eceff1; borderRadius:4px; borderLeft:3px solid #78909C">
<p style="bold:true; color:#37474F; fontSize:11; marginBottom:4px">'研发投入'</p>
<p style="fontSize:10; color:#455a64">'研发费用年均增长38.9%,占营收比例达13.3%'</p>
</div>
<div style="width:290px; margin:4px; padding:10px; backgroundColor:#eceff1; borderRadius:4px; borderLeft:3px solid #78909C">
<p style="bold:true; color:#37474F; fontSize:11; marginBottom:4px">'人才结构'</p>
<p style="fontSize:10; color:#455a64">'技术研发人员占比42%,硕士以上学历占35%'</p>
</div>
<div style="width:290px; margin:4px; padding:10px; backgroundColor:#eceff1; borderRadius:4px; borderLeft:3px solid #78909C">
<p style="bold:true; color:#37474F; fontSize:11; marginBottom:4px">'客户质量'</p>
<p style="fontSize:10; color:#455a64">'服务15家上市公司,客户续约率92%,大客户满意度4.8/5.0'</p>
</div>
<div style="width:290px; margin:4px; padding:10px; backgroundColor:#eceff1; borderRadius:4px; borderLeft:3px solid #78909C">
<p style="bold:true; color:#37474F; fontSize:11; marginBottom:4px">'资产质量'</p>
<p style="fontSize:10; color:#455a64">'资产负债率维持在38%左右,流动比率2.8,偿债能力良好'</p>
</div>
</div>
</div>
<div style="marginBottom:14px">
<h2 style="color:#546E7A; fontSize:13; bold:true; marginBottom:10px">'业务板块矩形树图'</h2>
<div style="textAlignment:center">
<svg style="width:500px;height:400px">${svg}</svg>
</div>
<div style="display:flex; justifyContent:space-between; marginTop:10px">
<div style="width:290px">
<div style="fontSize:10; color:#37474F; marginBottom:4px">
<span style="bold:true">'财务状况(90分): '</span>
'营收稳定增长'
</div>
<div style="fontSize:10; color:#37474F; marginBottom:4px">
<span style="bold:true">'经营能力(95分): '</span>
'客户留存率高'
</div>
</div>
<div style="width:290px">
<div style="fontSize:10; color:#37474F; marginBottom:4px">
<span style="bold:true">'偿债能力(85分): '</span>
'负债率合理'
</div>
<div style="fontSize:10; color:#37474F; marginBottom:4px">
<span style="bold:true">'发展潜力(92分): '</span>
'研发投入增加'
</div>
</div>
</div>
</div>
<div style="marginBottom:14px; backgroundColor:#eceff1; borderRadius:4px; padding:16px; borderLeft:4px solid #78909C">
<h2 style="color:#37474F; fontSize:13; bold:true; marginBottom:8px">'综合评价'</h2>
<p style="textAlignment:justify; fontSize:11">
'四川省泡海椒科技有限公司作为国家级高新技术企业和专精特新"小巨人"企业,在云计算和大数据领域表现出色。公司财务状况健康,经营能力突出,技术创新能力强,具备良好的发展潜力。信用评级为AAA级,展望稳定。'
</p>
</div>
<div style="marginTop:12px">
<p style="fontSize:9; color:#90a4ae">'本报告依据公开信息和专业评估模型生成,仅供参考 | 报告生成时间: 2025年09月06日'</p>
<p style="fontSize:9; color:#90a4ae">'© 2023 企业信用评估中心 版权所有 | 认证编号: CE-2023-001'</p>
</div>
</body>
</pdf>More demos in this group
The PDF, preview image, template and source code on this page were all produced by a real JQuick-Pdf run and are free to copy into your own project.