Customer segmentation pie (enterprise operations) — generate this PDF with Java (PIE)
PIE2 页 A4 · 149 KB
Groups customers by value tier and shows the concentration of high-value customers in a pie chart.

Output specs
- PDF pages
- 2
- Chart type
- PIE
- Template lines
- 75
- Source lines
- 86
Java source · JQuickBiz39CustomerSegmentPieTest.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.code.JTrigger;
import com.github.paohaijiao.config.JPdfConfig;
import com.github.paohaijiao.data.JData;
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.JPie;
import org.junit.Test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* 业务场景 Demo 39:客户分层饼图(企业运营 / 客户经营)
*
* <p>业务场景:企业运营平台按客户价值把活跃客户划分为战略客户、重点客户、成长客户、
* 一般客户、潜在客户五层,用于客户经营策略与资源投放决策,主色采用商务稳健蓝 #0D47A1。</p>
* <p>实际图表类型:{@link JChartType#PIE} 饼图(展示各客户层级的数量占比)。</p>
*
* <p>模板:{@code report/biz/39_customer_segment_pie.txt};图表以 SVG 文本形式绑定到模板的
* {@code ${svg}} 占位符,输出到 {@code D:\test\biz\39_customer_segment_pie.pdf}。</p>
*
* <p>图表尺寸说明:图表按 700pt × 400pt(宽 × 高)的方形比例设计;模板中 {@code <svg>}
* 只声明宽度、不声明高度,因此宽度被页面自动收窄时高度会按原比例同步缩放,不会纵向拉伸变形。</p>
*
* @author Martin
* @version 1.0.0
*/
public class JQuickBiz39CustomerSegmentPieTest {
public static final String path = JQuickConstant.path;
@Test
public void biz39CustomerSegmentPie() throws IOException {
JOption option = new JOption();
option.title().text("客户价值分层构成").subtext("2024年活跃客户分层分布(单位:户)");
option.tooltip().trigger(JTrigger.item);
JPie pie = new JPie("客户分层");
// 客户分层户数:呈金字塔结构,层级越高客户数越少但价值贡献越高
pie.data(
new JData().name("战略客户").value(86),
new JData().name("重点客户").value(412),
new JData().name("成长客户").value(1680),
new JData().name("一般客户").value(5260),
new JData().name("潜在客户").value(3140)
);
option.series(pie);
String svg = JChartRendererFactory.renderChart(JChartType.PIE, option);
File dir = new File(path + "biz");
if (!dir.exists()) {
dir.mkdirs();
}
FileOutputStream fileOutputStream = new FileOutputStream(path + "biz/39_customer_segment_pie.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/39_customer_segment_pie.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/39_customer_segment_pie.txt");Template file · 39_customer_segment_pie.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="background:#E9F0FA; border:1px solid #D6DEE8; borderLeft:6px solid #0D47A1; borderRadius:4px; padding:12px; marginBottom:10px">
<h1 style="color:#0D47A1; fontSize:17; bold:true; marginBottom:4px">'客户价值分层构成分析'</h1>
<p style="color:#5A6B7C; fontSize:9">'报告编号:CUS-2024-0918 | 生成日期:2024年10月10日 | 数据来源:客户经营分析平台'</p>
</div>
<h2 style="color:#0D47A1; fontSize:13; bold:true; underline:true; marginBottom:6px">'一、2024年活跃客户分层构成'</h2>
<div style="marginBottom:12px">
<div style="display:flex; justifyContent:center">
<svg style="width:700pt">${svg}</svg>
</div>
<p style="fontSize:9; color:#6c757d; italic:true; marginTop:4px">'图 1 2024年活跃客户分层分布(单位:户,统计口径:近12个月有交易或服务记录的客户)'</p>
</div>
<h2 style="color:#0D47A1; fontSize:13; bold:true; underline:true; marginBottom:6px">'二、客户分层明细'</h2>
<div style="marginBottom:12px">
<table style="width:540px; fontSize:10">
<tr>
<th style="width:150px; backgroundColor:#0D47A1; color:white; padding:6px; textAlign:center; border:1px solid #C3D5EC">'客户层级'</th>
<th style="width:130px; backgroundColor:#0D47A1; color:white; padding:6px; textAlign:center; border:1px solid #C3D5EC">'客户数(户)'</th>
<th style="width:130px; backgroundColor:#0D47A1; color:white; padding:6px; textAlign:center; border:1px solid #C3D5EC">'数量占比'</th>
<th style="width:130px; backgroundColor:#0D47A1; color:white; padding:6px; textAlign:center; border:1px solid #C3D5EC">'分层状态'</th>
</tr>
<tr>
<td style="padding:5px; border:1px solid #DCE3EC">'战略客户'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'86'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'0.8%'</td>
<td style="padding:5px; textAlign:right; color:#1B5E20; bold:true; border:1px solid #DCE3EC">'核心达标'</td>
</tr>
<tr>
<td style="padding:5px; border:1px solid #DCE3EC">'重点客户'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'412'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'3.9%'</td>
<td style="padding:5px; textAlign:right; color:#1B5E20; bold:true; border:1px solid #DCE3EC">'稳定达标'</td>
</tr>
<tr>
<td style="padding:5px; border:1px solid #DCE3EC">'成长客户'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'1,680'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'15.9%'</td>
<td style="padding:5px; textAlign:right; color:#1B5E20; bold:true; border:1px solid #DCE3EC">'规模达标'</td>
</tr>
<tr>
<td style="padding:5px; border:1px solid #DCE3EC">'一般客户'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'5,260'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'49.7%'</td>
<td style="padding:5px; textAlign:right; color:#BF360C; bold:true; border:1px solid #DCE3EC">'价值预警'</td>
</tr>
<tr>
<td style="padding:5px; border:1px solid #DCE3EC">'潜在客户'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'3,140'</td>
<td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'29.7%'</td>
<td style="padding:5px; textAlign:right; color:#BF360C; bold:true; border:1px solid #DCE3EC">'转化预警'</td>
</tr>
<tr>
<td style="padding:5px; bold:true; border:1px solid #DCE3EC">'合计'</td>
<td style="padding:5px; textAlign:right; bold:true; border:1px solid #DCE3EC">'10,578'</td>
<td style="padding:5px; textAlign:right; bold:true; border:1px solid #DCE3EC">'100.0%'</td>
<td style="padding:5px; textAlign:right; color:#1B5E20; bold:true; border:1px solid #DCE3EC">'整体达标'</td>
</tr>
</table>
</div>
<h2 style="color:#0D47A1; fontSize:13; bold:true; underline:true; marginBottom:6px">'三、客户经营策略建议'</h2>
<list style="paddingLeft:18px; fontSize:10" listType="ordered">
<li style="marginBottom:6px">'分层结构呈金字塔形:一般客户 5,260 户占 49.7%,潜在客户 3,140 户占 29.7%,两者合计接近八成,构成长尾基本盘。'</li>
<li style="marginBottom:6px">'高价值客户占比偏低:战略客户仅 86 户占 0.8%,重点客户 412 户占 3.9%,两者合计 4.7%,却是收入贡献的核心来源。'</li>
<li style="marginBottom:6px">'成长客户 1,680 户占 15.9%,是向上晋级的核心蓄水池,应优先投放行业解决方案与专属客户经理资源。'</li>
<li style="marginBottom:6px">'建议:对一般客户与潜在客户实施自动化分层运营,将人工服务资源集中投向战略与重点客户,力争高价值客户占比提升至 6%。'</li>
</list>
<p style="textAlignment:center; color:#8a939b; fontSize:8; italic:true; marginTop:10px">'数据来源:客户经营分析平台 | 生成时间:2024年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.