Skip to content

Regional quarterly sales, four-series comparison (sales operations) — generate this PDF with Java (MultipleBar)

JQuick-PdfBiz Demo

MultipleBar1 页 A4 · 223 KB

A grouped bar chart of East/North/South China and West region sales for October-December 2024, with value labels on the bars, a four-color legend at the bottom and monthly conclusions on regional leaders and growth.

Download the PDFView raw template fileBack to all demos

Regional quarterly sales, four-series comparison (sales operations) — MultipleBar
Rendered output

Output specs

PDF pages
1
Chart type
MultipleBar
Template lines
36
Source lines
104

Java source · JQuickBiz59FourBarTest.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.combol.JMultiBarChartData;
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.Arrays;

/**
 * 业务场景 Demo 59:分区域季度销售四系列对比(销售运营)
 *
 * <p>业务场景:销售运营部门对比华东、华北、华南、西部四大区域在 2024 年四季度
 * 各月的销售额,采用四系列分组柱状图并列展示。</p>
 * <p>实际图表类型:{@link JChartType#MultipleBar} 多系列分组柱状图。</p>
 *
 * <p>模板:{@code report/biz/59_fourBar.txt};图表以 SVG 文本形式绑定到模板的
 * {@code ${svg}} 占位符,输出到 {@code D:\test\biz\59_fourBar.pdf}。</p>
 *
 * <p>图表尺寸说明:图表按 700pt 宽的横版比例设计;模板中 {@code <svg>}
 * 只声明宽度、不声明高度,宽度被页面自动收窄时高度会按原比例同步缩放。</p>
 *
 * @author Martin
 * @version 1.0.0
 */
public class JQuickBiz59FourBarTest {

    public static final String path = JQuickConstant.path;

    @Test
    public void biz59FourBar() throws IOException {
        JMultiBarChartData chartData = new JMultiBarChartData();
        chartData.setTitleText("分区域季度销售四系列对比");
        chartData.setSubtitleText("华东 / 华北 / 华南 / 西部  2024 年 10-12 月销售额(万元)");
        chartData.setXAxisLabels(Arrays.asList("10月", "11月", "12月"));
        chartData.setXAxisTitle("月份");
        chartData.setYAxisTitle("销售额(万元)");
        chartData.setFooterText("数据来源:销售运营系统 | 统计口径:自然月");

        JMultiBarChartData.BarData east = new JMultiBarChartData.BarData();
        east.setLegendText("华东");
        east.setBarColor(new Color(230, 81, 0));
        east.setValues(Arrays.asList(780.0, 830.0, 910.0));

        JMultiBarChartData.BarData north = new JMultiBarChartData.BarData();
        north.setLegendText("华北");
        north.setBarColor(new Color(251, 140, 0));
        north.setValues(Arrays.asList(560.0, 590.0, 570.0));

        JMultiBarChartData.BarData south = new JMultiBarChartData.BarData();
        south.setLegendText("华南");
        south.setBarColor(new Color(255, 183, 77));
        south.setValues(Arrays.asList(620.0, 660.0, 720.0));

        JMultiBarChartData.BarData west = new JMultiBarChartData.BarData();
        west.setLegendText("西部");
        west.setBarColor(new Color(255, 213, 79));
        west.setValues(Arrays.asList(310.0, 380.0, 460.0));

        chartData.setBarDataList(Arrays.asList(east, north, south, west));

        JOption option = new JOption();
        option.setData(chartData);

        String svg = JChartRendererFactory.renderChart(JChartType.MultipleBar, option);

        File dir = new File(path + "biz");
        if (!dir.exists()) {
            dir.mkdirs();
        }
        FileOutputStream fileOutputStream = new FileOutputStream(path + "biz/59_fourBar.pdf");
        JPdfConfig config = new JPdfConfig();
        config.getLayoutConfig().setFlexLayout(true);
        JQuickPdfFactory factory = new JQuickPdfFactory(config);
        factory.bind("svg", svg);
        byte[] bytes = factory.executeResource("report/biz/59_fourBar.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/59_fourBar.txt");

Template file · 59_fourBar.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>
  // 59 四系列柱状图 Demo:同一维度下并列展示四个系列的数值对比
  <div style="background:#E65100; padding:12px; borderRadius:4px; marginBottom:10px; keepTogether:true">
    <div style="display:flex; justifyContent:space-between">
      <div style="width:320px">
        <h1 style="color:white; fontSize:17; bold:true; marginBottom:3px">'分区域季度销售四系列对比'</h1>
        <p style="color:#FFCCBC; fontSize:9">'华东 / 华北 / 华南 / 西部 四大区域,2024 年四季度各月销售额'</p>
      </div>
      <div style="width:220px; textAlignment:right; borderLeft:1px solid #FFAB91; paddingLeft:10px">
        <p style="color:white; fontSize:9">'统计周期:2024 年 10-12 月'</p>
        <p style="color:#FFCCBC; fontSize:9">'单位:万元'</p>
        <p style="color:#FFCCBC; fontSize:9">'编制:销售运营部'</p>
      </div>
    </div>
  </div>

  <div style="marginBottom:10px; padding:10px; backgroundColor:#F7F9FC; borderRadius:4px; borderTop:2px solid #E65100">
    <h2 style="color:#E65100; marginBottom:6px; fontSize:13; bold:true">'一、各区域月度销售额对比'</h2>
    <div style="display:flex; justifyContent:center">
      <svg style="width:700pt">${svg}</svg>
    </div>
    <p style="fontSize:9; color:#6c757d; italic:true; marginTop:6px">'图 1  四系列分组柱状图:每组四根柱分别代表华东、华北、华南、西部销售额'</p>
  </div>

  <list style="listStyleType:disc; paddingLeft:16px; fontSize:10">
    <li style="marginBottom:6px"><span style="bold:true; color:#E65100">'华东持续领先:'</span>'连续三个月销售额居首,12 月突破 900 万。'</li>
    <li style="marginBottom:6px"><span style="bold:true; color:#E65100">'西部增速最快:'</span>'10 月至 12 月环比增长显著,市场拓展初见成效。'</li>
    <li style="marginBottom:6px"><span style="bold:true; color:#E65100">'建议:'</span>'华北区域 12 月略有回落,需关注重点客户续约情况。'</li>
  </list>

  <lineSeparator style="strokeColor:#DCE3EC"></lineSeparator>
  <p style="color:#6c757d; fontSize:8; textAlignment:center; marginTop:6px">'生成时间:2025年1月6日 | 批准人:销售总监'</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.