Service handling duration distribution (government service windows) — generate this PDF with Java (BAR)
BAR2 页 A4 · 189 KB
Buckets transactions by handling duration and uses a bar chart to find the most time-consuming service types.

Output specs
- PDF pages
- 2
- Chart type
- BAR
- Template lines
- 129
- Source lines
- 85
Java source · JQuickBiz34HandleDurationTest.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.axis.JValueAxis;
import com.github.paohaijiao.code.JTrigger;
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.JBar;
import org.junit.Test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* 业务场景 Demo 34:业务办理时长分布(政务窗口服务)
*
* <p>业务场景:政务窗口按办理时长区间统计业务办件量,用于分析窗口服务效率与长尾事项。</p>
* <p>实际图表类型:{@link JChartType#BAR} 柱状图。<b>jquick-pdf 无直方图(Histogram)渲染器,
* 实际使用柱状图 BAR 替代直方图</b>:预先将时长分箱,以「时长区间」为类目、「办件量」为柱高呈现分布形态。</p>
*
* <p>模板:{@code report/biz/34_handle_duration.txt};图表以 SVG 文本形式绑定到模板的
* {@code ${svg}} 占位符,输出到 {@code D:\test\biz\34_handle_duration.pdf}。</p>
*
* <p>图表尺寸说明:图表按 700pt × 380pt(宽 × 高)的横版比例设计;模板中 {@code <svg>}
* 只声明宽度、不声明高度,因此宽度被页面自动收窄时高度会按原比例同步缩放,不会纵向拉伸变形。</p>
*
* @author Martin
* @version 1.0.0
*/
public class JQuickBiz34HandleDurationTest {
public static final String path = JQuickConstant.path;
@Test
public void biz34HandleDuration() throws IOException {
JOption option = new JOption();
option.title().text("业务办理时长分布").subtext("按办理时长区间统计办件量(单位:件)");
option.tooltip().trigger(JTrigger.axis);
JCategoryAxis xAxis = new JCategoryAxis();
// 时长分箱作为类目,用柱状图替代直方图呈现分布
xAxis.data("0-15分钟", "15-30分钟", "30-45分钟", "45-60分钟", "60-90分钟", "90-120分钟", "120分钟以上");
option.xAxis(xAxis);
option.yAxis(new JValueAxis());
JBar count = new JBar();
count.name("办件量").data(4120, 8360, 6240, 3180, 1520, 640, 210);
option.series(count);
String svg = JChartRendererFactory.renderChart(JChartType.BAR, option);
File dir = new File(path + "biz");
if (!dir.exists()) {
dir.mkdirs();
}
FileOutputStream fileOutputStream = new FileOutputStream(path + "biz/34_handle_duration.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/34_handle_duration.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/34_handle_duration.txt");Template file · 34_handle_duration.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="borderBottom:2px solid #00695C; paddingBottom:8px; marginBottom:10px">
<div style="display:flex; justifyContent:space-between">
<div style="width:150px">
<p style="color:#00695C; fontSize:10pt; bold:true">'市政务服务中心'</p>
</div>
<div style="width:250px; textAlignment:center">
<h1 style="color:#00695C; fontSize:16pt; bold:true; textAlignment:center">'业务办理时长分布报告'</h1>
</div>
<div style="width:150px; textAlignment:right">
<p style="color:#6c757d; fontSize:9pt">'2025年10月10日'</p>
</div>
</div>
</div>
<div style="marginBottom:10px">
<h2 style="color:#00695C; fontSize:13pt; bold:true; underline:true; marginBottom:6pt">'一、关键效能指标'</h2>
<div style="display:flex; justifyContent:space-between; marginBottom:12px; keepTogether:true">
<div style="width:132px; minHeight:56px; background:#E6F2F0; borderRadius:4px; padding:8px; verticalAlignment:middle">
<p style="color:#00695C; fontSize:16pt; bold:true; textAlignment:center; marginBottom:2px">'24,270'</p>
<p style="color:#5A6B7C; fontSize:9pt; textAlignment:center">'本期办结业务量(件)'</p>
</div>
<div style="width:132px; minHeight:56px; background:#E6F2F0; borderRadius:4px; padding:8px; verticalAlignment:middle">
<p style="color:#00695C; fontSize:16pt; bold:true; textAlignment:center; marginBottom:2px">'34.2'</p>
<p style="color:#5A6B7C; fontSize:9pt; textAlignment:center">'平均办理时长(分钟)'</p>
</div>
<div style="width:132px; minHeight:56px; background:#E6F2F0; borderRadius:4px; padding:8px; verticalAlignment:middle">
<p style="color:#00695C; fontSize:16pt; bold:true; textAlignment:center; marginBottom:2px">'77.1%'</p>
<p style="color:#5A6B7C; fontSize:9pt; textAlignment:center">'45分钟内办结率'</p>
</div>
<div style="width:132px; minHeight:56px; background:#E6F2F0; borderRadius:4px; padding:8px; verticalAlignment:middle">
<p style="color:#BF360C; fontSize:16pt; bold:true; textAlignment:center; marginBottom:2px">'9.8%'</p>
<p style="color:#5A6B7C; fontSize:9pt; textAlignment:center">'超60分钟办结占比'</p>
</div>
</div>
</div>
<div style="marginBottom:10px; padding:10px; backgroundColor:#F7FBFA; borderRadius:4px">
<h2 style="color:#00695C; fontSize:13pt; bold:true; underline:true; marginTop:0; marginBottom:6pt">'二、办理时长区间分布'</h2>
<div style="display:flex; justifyContent:center">
<svg style="width:700pt">${svg}</svg>
</div>
<p style="fontSize:9pt; color:#6c757d; italic:true; marginTop:6pt">'图 1 办理时长区间分布(直方图替代视图:jquick-pdf 无直方图渲染器,以柱状图 BAR 按分箱呈现分布形态)'</p>
</div>
<div style="marginBottom:10px">
<h2 style="color:#00695C; fontSize:13pt; bold:true; underline:true; marginBottom:6pt">'三、区间明细与累计分布'</h2>
<table style="width:540px; fontSize:10pt">
<tr>
<th style="backgroundColor:#00695C; color:white; padding:6px; textAlign:center; border:1px solid #DCE3EC">'办理时长区间'</th>
<th style="backgroundColor:#00695C; color:white; padding:6px; textAlign:center; border:1px solid #DCE3EC">'办件量(件)'</th>
<th style="backgroundColor:#00695C; color:white; padding:6px; textAlign:center; border:1px solid #DCE3EC">'占比'</th>
<th style="backgroundColor:#00695C; color:white; padding:6px; textAlign:center; border:1px solid #DCE3EC">'累计占比'</th>
<th style="backgroundColor:#00695C; color:white; padding:6px; textAlign:center; border:1px solid #DCE3EC">'评价'</th>
</tr>
<tr>
<td style="padding:5px; border:1px solid #DCE3EC">'0-15分钟'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'4,120'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'17.0%'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'17.0%'</td>
<td style="padding:5px; textAlign:center; border:1px solid #DCE3EC">'达标'</td>
</tr>
<tr>
<td style="padding:5px; backgroundColor:#E6F2F0; border:1px solid #DCE3EC">'15-30分钟'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#E6F2F0; border:1px solid #DCE3EC">'8,360'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#E6F2F0; border:1px solid #DCE3EC">'34.4%'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#E6F2F0; border:1px solid #DCE3EC">'51.4%'</td>
<td style="padding:5px; textAlign:center; backgroundColor:#E6F2F0; border:1px solid #DCE3EC">'达标'</td>
</tr>
<tr>
<td style="padding:5px; border:1px solid #DCE3EC">'30-45分钟'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'6,240'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'25.7%'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'77.1%'</td>
<td style="padding:5px; textAlign:center; border:1px solid #DCE3EC">'达标'</td>
</tr>
<tr>
<td style="padding:5px; backgroundColor:#E6F2F0; border:1px solid #DCE3EC">'45-60分钟'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#E6F2F0; border:1px solid #DCE3EC">'3,180'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#E6F2F0; border:1px solid #DCE3EC">'13.1%'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#E6F2F0; border:1px solid #DCE3EC">'90.2%'</td>
<td style="padding:5px; textAlign:center; backgroundColor:#E6F2F0; border:1px solid #DCE3EC">'预警'</td>
</tr>
<tr>
<td style="padding:5px; border:1px solid #DCE3EC">'60-90分钟'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'1,520'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'6.3%'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'96.5%'</td>
<td style="padding:5px; textAlign:center; border:1px solid #DCE3EC">'预警'</td>
</tr>
<tr>
<td style="padding:5px; backgroundColor:#E6F2F0; border:1px solid #DCE3EC">'90-120分钟'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#E6F2F0; border:1px solid #DCE3EC">'640'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#E6F2F0; border:1px solid #DCE3EC">'2.6%'</td>
<td style="padding:5px; textAlign:right; backgroundColor:#E6F2F0; border:1px solid #DCE3EC">'99.1%'</td>
<td style="padding:5px; textAlign:center; backgroundColor:#E6F2F0; border:1px solid #DCE3EC">'预警'</td>
</tr>
<tr>
<td style="padding:5px; border:1px solid #DCE3EC">'120分钟以上'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'210'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'0.9%'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'100.0%'</td>
<td style="padding:5px; textAlign:center; border:1px solid #DCE3EC">'预警'</td>
</tr>
<tr>
<td style="padding:6px; backgroundColor:#00695C; color:white; bold:true; border:1px solid #00695C">'全量合计'</td>
<td style="padding:6px; textAlign:right; backgroundColor:#00695C; color:white; bold:true; border:1px solid #00695C">'24,270'</td>
<td style="padding:6px; textAlign:right; backgroundColor:#00695C; color:white; bold:true; border:1px solid #00695C">'100.0%'</td>
<td style="padding:6px; textAlign:right; backgroundColor:#00695C; color:white; bold:true; border:1px solid #00695C">'100.0%'</td>
<td style="padding:6px; textAlign:center; backgroundColor:#00695C; color:white; bold:true; border:1px solid #00695C">'达标率 77.1%'</td>
</tr>
</table>
</div>
<div style="marginBottom:10px">
<h2 style="color:#00695C; fontSize:13pt; bold:true; underline:true; marginBottom:6pt">'四、结论与改进建议'</h2>
<list style="listStyleType:disc; paddingLeft:16px; fontSize:10pt">
<li style="marginBottom:5px">'分布呈明显右偏:峰值落在 15-30 分钟区间(8,360 件、占 34.4%),30 分钟内办结占比 51.4%,45 分钟内达 77.1%。'</li>
<li style="marginBottom:5px">'整体效率改善:本期平均办理时长 34.2 分钟,较上年同期缩短约 4 分钟,窗口服务标准化成效显现。'</li>
<li style="marginBottom:5px">'长尾事项需分流:60 分钟以上共 2,370 件、占 9.8%,其中 120 分钟以上 210 件多集中于不动产登记、企业开办等复杂事项。'</li>
<li style="marginBottom:5px">'建议对 45 分钟以上区间占比高的窗口开展材料预审环节排查,并设立复杂事项专窗以压缩长尾时长。'</li>
</list>
</div>
<p style="textAlignment:center; color:#8a939b; fontSize:8pt; italic:true; marginTop:10px">'数据来源:政务大厅一窗受理平台 | 生成时间:2025年10月10日 | 密级:内部'</p>
</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.