Business metric heat matrix (enterprise operations) — generate this PDF with Java (HEATMAP)
HEATMAP2 页 A4 · 148 KB
Builds a month-by-metric matrix and uses heatmap intensity to surface unusual combinations quickly.

Output specs
- PDF pages
- 2
- Chart type
- HEATMAP
- Template lines
- 126
- Source lines
- 90
Java source · JQuickBiz27MetricHeatmapTest.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.biz;
import com.github.paohaijiao.JOption;
import com.github.paohaijiao.axis.JCategoryAxis;
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.series.JHeatmap;
import org.junit.Test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* 业务场景 Demo 27:企业运营业务指标热力矩阵(企业运营)
*
* <p>业务场景:企业运营管理系统按"业务线 × 月份"汇总营业收入,通过颜色深浅识别各业务线的
* 淡旺季规律,为资源投放与营销排期提供依据。</p>
* <p>实际图表类型:{@link JChartType#HEATMAP} 热力图(矩阵单元格颜色越深表示营收越高)。</p>
*
* <p>模板:{@code report/biz/27_metric_heatmap.txt};图表以 SVG 文本形式绑定到模板的
* {@code ${svg}} 占位符,输出到 {@code D:\test\biz\27_metric_heatmap.pdf}。</p>
*
* <p>图表尺寸说明:图表按 700pt × 400pt(宽 × 高)的横版比例设计;模板中 {@code <svg>}
* 只声明宽度、不声明高度,因此宽度被页面自动收窄时高度会按原比例同步缩放,不会纵向拉伸变形。</p>
*
* @author Martin
* @version 1.0.0
*/
public class JQuickBiz27MetricHeatmapTest {
public static final String path = JQuickConstant.path;
@Test
public void biz27MetricHeatmap() throws IOException {
JOption option = new JOption();
option.title("业务指标热力矩阵", "各业务线月度营业收入(万元)");
// xAxis 为列(月份),yAxis 为行(业务线)
option.xAxis(new JCategoryAxis().data("1月", "2月", "3月", "4月", "5月", "6月"));
option.yAxis(new JCategoryAxis().data("零售金融", "公司金融", "财富管理", "支付结算"));
JHeatmap heatmap = new JHeatmap();
// 每个元素为 Object[]{行索引(yAxis), 列索引(xAxis), 数值},覆盖 4 行 × 6 列 = 24 个数据点
heatmap.data(
new Object[]{0, 0, 1860}, new Object[]{0, 1, 1420}, new Object[]{0, 2, 2140},
new Object[]{0, 3, 2280}, new Object[]{0, 4, 2360}, new Object[]{0, 5, 2520},
new Object[]{1, 0, 1240}, new Object[]{1, 1, 980}, new Object[]{1, 2, 1680},
new Object[]{1, 3, 1820}, new Object[]{1, 4, 1940}, new Object[]{1, 5, 2160},
new Object[]{2, 0, 860}, new Object[]{2, 1, 1120}, new Object[]{2, 2, 940},
new Object[]{2, 3, 880}, new Object[]{2, 4, 910}, new Object[]{2, 5, 1020},
new Object[]{3, 0, 2380}, new Object[]{3, 1, 1960}, new Object[]{3, 2, 2460},
new Object[]{3, 3, 2580}, new Object[]{3, 4, 2720}, new Object[]{3, 5, 2860}
);
option.series(heatmap);
String svg = JChartRendererFactory.renderChart(JChartType.HEATMAP, option);
File dir = new File(path + "biz");
if (!dir.exists()) {
dir.mkdirs();
}
FileOutputStream fileOutputStream = new FileOutputStream(path + "biz/27_metric_heatmap.pdf");
JPdfConfig config = new JPdfConfig();
// 开启 flex 行布局,使模板中的 display:flex 生效(图表居中)
config.getLayoutConfig().setFlexLayout(true);
JQuickPdfFactory factory = new JQuickPdfFactory(config);
factory.bind("svg", svg);
byte[] bytes = factory.executeResource("report/biz/27_metric_heatmap.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/biz/27_metric_heatmap.txt");Template file · 27_metric_heatmap.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="marginBottom:12px; borderBottom:4px solid #4E342E; paddingBottom:8px; keepTogether:true">
<h1 style="color:#4E342E; fontSize:19; bold:true; marginBottom:4px">'业务指标热力矩阵'</h1>
<div style="display:flex; justifyContent:space-between">
<div style="width:290px">
<p style="color:#6c757d; fontSize:9">'各业务线月度营业收入(单位:万元)'</p>
</div>
<div style="width:250px; textAlignment:right">
<p style="color:#6c757d; fontSize:9">'统计周期:2024年1月 - 6月 | 数据来源:运营数据中台'</p>
</div>
</div>
</div>
<div style="display:flex; justifyContent:space-between; marginBottom:12px; keepTogether:true">
<div style="width:132px; minHeight:54px; background:#F5F0EE; borderRadius:4px; padding:8px; verticalAlignment:middle">
<p style="color:#4E342E; fontSize:16; bold:true; textAlignment:center; marginBottom:2px">'43,090'</p>
<p style="color:#5A6B7C; fontSize:9; textAlignment:center">'上半年营收合计(万元)'</p>
</div>
<div style="width:132px; minHeight:54px; background:#F5F0EE; borderRadius:4px; padding:8px; verticalAlignment:middle">
<p style="color:#1B5E20; fontSize:16; bold:true; textAlignment:center; marginBottom:2px">'2,860'</p>
<p style="color:#5A6B7C; fontSize:9; textAlignment:center">'峰值:支付结算6月'</p>
</div>
<div style="width:132px; minHeight:54px; background:#F5F0EE; borderRadius:4px; padding:8px; verticalAlignment:middle">
<p style="color:#BF360C; fontSize:16; bold:true; textAlignment:center; marginBottom:2px">'860'</p>
<p style="color:#5A6B7C; fontSize:9; textAlignment:center">'低谷:财富管理1月'</p>
</div>
<div style="width:132px; minHeight:54px; background:#F5F0EE; borderRadius:4px; padding:8px; verticalAlignment:middle">
<p style="color:#4E342E; fontSize:16; bold:true; textAlignment:center; marginBottom:2px">'14,960'</p>
<p style="color:#5A6B7C; fontSize:9; textAlignment:center">'最大业务线:支付结算'</p>
</div>
</div>
<div style="marginBottom:12px">
<div style="borderLeft:4px solid #4E342E; paddingLeft:8px; marginBottom:8px">
<h2 style="color:#4E342E; fontSize:13; bold:true; marginTop:0; marginBottom:0">'一、业务指标热力矩阵'</h2>
</div>
<div style="display:flex; justifyContent:center">
<svg style="width:700pt">${svg}</svg>
</div>
<p style="fontSize:9; color:#6c757d; italic:true; marginTop:6px">'图 1 四条业务线 1-6 月营业收入热力图(颜色越深营收越高;数据来源:运营数据中台)'</p>
</div>
<div style="marginBottom:12px">
<div style="borderLeft:4px solid #4E342E; paddingLeft:8px; marginBottom:8px">
<h2 style="color:#4E342E; fontSize:13; bold:true; marginTop:0; marginBottom:0">'二、分业务线月度营收明细'</h2>
</div>
<table style="width:540px; fontSize:10">
<tr>
<th style="backgroundColor:#4E342E; color:white; padding:5px; textAlign:center; border:1px solid #DCE3EC">'业务线'</th>
<th style="backgroundColor:#4E342E; color:white; padding:5px; textAlign:center; border:1px solid #DCE3EC">'1月'</th>
<th style="backgroundColor:#4E342E; color:white; padding:5px; textAlign:center; border:1px solid #DCE3EC">'2月'</th>
<th style="backgroundColor:#4E342E; color:white; padding:5px; textAlign:center; border:1px solid #DCE3EC">'3月'</th>
<th style="backgroundColor:#4E342E; color:white; padding:5px; textAlign:center; border:1px solid #DCE3EC">'4月'</th>
<th style="backgroundColor:#4E342E; color:white; padding:5px; textAlign:center; border:1px solid #DCE3EC">'5月'</th>
<th style="backgroundColor:#4E342E; color:white; padding:5px; textAlign:center; border:1px solid #DCE3EC">'6月'</th>
<th style="backgroundColor:#4E342E; color:white; padding:5px; textAlign:center; border:1px solid #DCE3EC">'合计'</th>
</tr>
<tr>
<td style="width:96px; border:1px solid #DCE3EC; borderLeft:3px solid #4E342E; padding:5px">'零售金融'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'1,860'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'1,420'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'2,140'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'2,280'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'2,360'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'2,520'</td>
<td style="padding:5px; textAlign:right; bold:true; border:1px solid #DCE3EC">'12,580'</td>
</tr>
<tr>
<td style="width:96px; backgroundColor:#F5F0EE; border:1px solid #DCE3EC; borderLeft:3px solid #4E342E; padding:5px">'公司金融'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'1,240'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'980'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'1,680'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'1,820'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'1,940'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'2,160'</td>
<td style="padding:5px; textAlign:right; bold:true; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'9,820'</td>
</tr>
<tr>
<td style="width:96px; border:1px solid #DCE3EC; borderLeft:3px solid #4E342E; padding:5px">'财富管理'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'860'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'1,120'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'940'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'880'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'910'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'1,020'</td>
<td style="padding:5px; textAlign:right; bold:true; border:1px solid #DCE3EC">'5,730'</td>
</tr>
<tr>
<td style="width:96px; backgroundColor:#F5F0EE; border:1px solid #DCE3EC; borderLeft:3px solid #4E342E; padding:5px">'支付结算'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'2,380'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'1,960'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'2,460'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'2,580'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'2,720'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'2,860'</td>
<td style="padding:5px; textAlign:right; bold:true; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'14,960'</td>
</tr>
<tr>
<td style="width:96px; backgroundColor:#F5F0EE; border:1px solid #DCE3EC; borderLeft:3px solid #4E342E; padding:6px; bold:true">'合计'</td>
<td style="padding:6px; textAlign:right; bold:true; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'6,340'</td>
<td style="padding:6px; textAlign:right; bold:true; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'5,480'</td>
<td style="padding:6px; textAlign:right; bold:true; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'7,220'</td>
<td style="padding:6px; textAlign:right; bold:true; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'7,560'</td>
<td style="padding:6px; textAlign:right; bold:true; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'7,930'</td>
<td style="padding:6px; textAlign:right; bold:true; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'8,560'</td>
<td style="padding:6px; textAlign:right; bold:true; backgroundColor:#F5F0EE; border:1px solid #DCE3EC">'43,090'</td>
</tr>
</table>
</div>
<div style="marginBottom:10px">
<div style="borderLeft:4px solid #4E342E; paddingLeft:8px; marginBottom:8px">
<h2 style="color:#4E342E; fontSize:13; bold:true; marginTop:0; marginBottom:0">'三、业务洞察与资源建议'</h2>
</div>
<list style="list-style-type:none; padding-left:0; fontSize:10">
<li style="marginBottom:6px"><span style="bold:true; color:#4E342E">'规模格局:'</span>'支付结算 14,960 万元居首,零售金融 12,580 万元次之,两者合计占四线营收的 63.9%。'</li>
<li style="marginBottom:6px"><span style="bold:true; color:#4E342E">'淡旺季:'</span>'2月为全行业低谷(四线合计 5,480 万元),6月冲高至 8,560 万元,环比 1月增长 35.0%。'</li>
<li style="marginBottom:6px"><span style="bold:true; color:#4E342E">'财富管理承压:'</span>'上半年仅 5,730 万元,且3-5月连续低于千万元,是唯一未呈现单边上行的业务线。'</li>
<li style="marginBottom:6px"><span style="bold:true; color:#4E342E">'建议:'</span>'三季度将营销资源向财富管理倾斜,并把支付结算的旺季运维排期提前至 5 月中旬。'</li>
</list>
<p style="textAlignment:right; color:#8a939b; fontSize:8; marginTop:8px">'注:表格数值与热力图单元格一一对应,单位为万元,四舍五入至整数。'</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.