Skip to content

Annual budget execution dashboard (government / corporate finance) — generate this PDF with Java (HorizontalBar)

JQuick-PdfBiz Demo

HorizontalBar2 页 A4 · 137 KB

Compares budget execution per department with horizontal bars to pinpoint departments that lag behind.

Download the PDFView raw template fileBack to all demos

Annual budget execution dashboard (government / corporate finance) — HorizontalBar
Rendered output

Output specs

PDF pages
2
Chart type
HorizontalBar
Template lines
92
Source lines
92

Java source · JQuickBiz24BudgetProgressTest.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.JHorizontalBarChartData;
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.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 业务场景 Demo 24:年度预算执行进度仪表盘(政务/企业财务)
 *
 * <p>业务场景:市财政局预算管理科跟踪各业务部门年度预算下达额与已执行额,用于市政府常务会议预算执行进度汇报。</p>
 * <p>实际图表类型:{@link JChartType#HorizontalBar} 横向条形图。jquick-pdf 暂无进度图(进度条)渲染器,
 * 因此用「预算下达 vs 已执行」两条横向条形并列的方式替代进度图,执行率由两段条形的长度对比直观呈现。</p>
 *
 * <p>模板:{@code report/biz/24_budget_progress.txt};图表以 SVG 文本形式绑定到模板的
 * {@code ${svg}} 占位符,输出到 {@code D:\test\biz\24_budget_progress.pdf}。</p>
 *
 * <p>图表尺寸说明:图表按 700pt 宽的横版比例设计;模板中 {@code <svg>} 只声明宽度、不声明高度,
 * 宽度被页面自动收窄时高度会按原比例同步缩放,不会纵向拉伸变形。</p>
 *
 * @author Martin
 * @version 1.0.0
 */
public class JQuickBiz24BudgetProgressTest {

    public static final String path = JQuickConstant.path;

    @Test
    public void biz24BudgetProgress() throws IOException {
        JHorizontalBarChartData chartData = new JHorizontalBarChartData();
        chartData.setTitleText("2024年度各部门预算执行进度");
        chartData.setSubtitleText("预算下达额与已执行额对比(截至2024年9月30日)");
        chartData.setXAxisTitle("金额(万元)");
        chartData.setYAxisTitle("部门");
        chartData.setValueWithPercent(false);
        chartData.setShowDataLabels(true);
        chartData.addYAxisLabel("教育局");
        chartData.addYAxisLabel("卫健委");
        chartData.addYAxisLabel("交通局");
        chartData.addYAxisLabel("农业农村局");
        chartData.addYAxisLabel("民政局");
        // 两条系列分别表示预算下达额与已执行额,颜色沿用政务系统低饱和主色
        List<Double> budget = Arrays.asList(12800.0, 9600.0, 8400.0, 6200.0, 5100.0);
        List<Double> executed = Arrays.asList(11260.0, 8120.0, 6930.0, 5480.0, 4320.0);
        chartData.addBarData(new JHorizontalBarChartData.BarData("预算下达", budget, JHorizontalBarChartData.COLOR_A));
        chartData.addBarData(new JHorizontalBarChartData.BarData("已执行", executed, JHorizontalBarChartData.COLOR_B));
        JOption option = new JOption();
        option.setData(chartData);

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

        File dir = new File(path + "biz");
        if (!dir.exists()) {
            dir.mkdirs();
        }
        FileOutputStream fileOutputStream = new FileOutputStream(path + "biz/24_budget_progress.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/24_budget_progress.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/24_budget_progress.txt");

Template file · 24_budget_progress.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="textAlignment:center; marginBottom:12px; padding:14px; background:#1F4E79; borderRadius:4px; keepTogether:true">
    <h1 style="textAlignment:center; color:white; marginBottom:6px; fontSize:18; bold:true">'2024年度各部门预算执行进度'</h1>
    <p style="textAlignment:center; color:white; fontSize:10; margin:2px">'预算下达额与已执行额对比(截至2024年9月30日,单位:万元)'</p>
    <p style="textAlignment:center; color:#CFE0EF; fontSize:10; margin:2px">'编制单位:市财政局预算管理科 | 报送对象:市政府常务会议'</p>
  </div>

  <div style="marginBottom:12px">
    <div style="backgroundColor:#E8F0F7; padding:6px 10px; borderRadius:3px; marginBottom:8px">
      <h2 style="color:#1F4E79; 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  五个业务部门预算下达与已执行对比(数据来源:预算管理一体化系统)'</p>
  </div>

  <div style="marginBottom:12px">
    <div style="backgroundColor:#E8F0F7; padding:6px 10px; borderRadius:3px; marginBottom:8px">
      <h2 style="color:#1F4E79; fontSize:13; bold:true; marginTop:0; marginBottom:0">'二、分部门预算执行明细'</h2>
    </div>
    <table style="width:540px; fontSize:10">
      <tr>
        <th style="backgroundColor:#1F4E79; color:white; padding:6px; textAlign:center; border:1px solid #DCE3EC">'部门'</th>
        <th style="backgroundColor:#1F4E79; color:white; padding:6px; textAlign:center; border:1px solid #DCE3EC">'预算下达(万元)'</th>
        <th style="backgroundColor:#1F4E79; color:white; padding:6px; textAlign:center; border:1px solid #DCE3EC">'已执行(万元)'</th>
        <th style="backgroundColor:#1F4E79; color:white; padding:6px; textAlign:center; border:1px solid #DCE3EC">'执行率'</th>
        <th style="backgroundColor:#1F4E79; color:white; padding:6px; textAlign:center; border:1px solid #DCE3EC">'进度评价'</th>
      </tr>
      <tr>
        <td style="padding:5px; border:1px solid #DCE3EC">'教育局'</td>
        <td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'12,800'</td>
        <td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'11,260'</td>
        <td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'87.97%'</td>
        <td style="padding:5px; color:#1B5E20; bold:true; border:1px solid #DCE3EC">'进度达标'</td>
      </tr>
      <tr>
        <td style="padding:5px; backgroundColor:#E8F0F7; border:1px solid #DCE3EC">'卫健委'</td>
        <td style="padding:5px; textAlign:right; backgroundColor:#E8F0F7; border:1px solid #DCE3EC">'9,600'</td>
        <td style="padding:5px; textAlign:right; backgroundColor:#E8F0F7; border:1px solid #DCE3EC">'8,120'</td>
        <td style="padding:5px; textAlign:right; backgroundColor:#E8F0F7; border:1px solid #DCE3EC">'84.58%'</td>
        <td style="padding:5px; backgroundColor:#E8F0F7; 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">'8,400'</td>
        <td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'6,930'</td>
        <td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'82.50%'</td>
        <td style="padding:5px; color:#BF360C; bold:true; border:1px solid #DCE3EC">'预警关注'</td>
      </tr>
      <tr>
        <td style="padding:5px; backgroundColor:#E8F0F7; border:1px solid #DCE3EC">'农业农村局'</td>
        <td style="padding:5px; textAlign:right; backgroundColor:#E8F0F7; border:1px solid #DCE3EC">'6,200'</td>
        <td style="padding:5px; textAlign:right; backgroundColor:#E8F0F7; border:1px solid #DCE3EC">'5,480'</td>
        <td style="padding:5px; textAlign:right; backgroundColor:#E8F0F7; border:1px solid #DCE3EC">'88.39%'</td>
        <td style="padding:5px; backgroundColor:#E8F0F7; 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,100'</td>
        <td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'4,320'</td>
        <td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'84.71%'</td>
        <td style="padding:5px; color:#1B5E20; bold:true; border:1px solid #DCE3EC">'正常推进'</td>
      </tr>
      <tr>
        <td style="padding:6px; backgroundColor:#E8F0F7; bold:true; border:1px solid #DCE3EC">'合计'</td>
        <td style="padding:6px; textAlign:right; backgroundColor:#E8F0F7; bold:true; border:1px solid #DCE3EC">'42,100'</td>
        <td style="padding:6px; textAlign:right; backgroundColor:#E8F0F7; bold:true; border:1px solid #DCE3EC">'36,110'</td>
        <td style="padding:6px; textAlign:right; backgroundColor:#E8F0F7; bold:true; border:1px solid #DCE3EC">'85.77%'</td>
        <td style="padding:6px; backgroundColor:#E8F0F7; color:#1B5E20; bold:true; border:1px solid #DCE3EC">'总体达标'</td>
      </tr>
    </table>
  </div>

  <div style="marginBottom:10px">
    <div style="backgroundColor:#E8F0F7; padding:6px 10px; borderRadius:3px; marginBottom:8px">
      <h2 style="color:#1F4E79; fontSize:13; bold:true; marginTop:0; marginBottom:0">'三、进度分析与下半年建议'</h2>
    </div>
    <list style="list-style-type:none; padding-left:0; fontSize:10">
      <li style="borderTop:1px dashed #C7C7C7; paddingTop:6px; marginBottom:6px">'总体进度:五个部门预算下达合计 42,100 万元,已执行 36,110 万元,整体执行率 85.77%,略高于序时进度。'</li>
      <li style="borderTop:1px dashed #C7C7C7; paddingTop:6px; marginBottom:6px">'领先部门:农业农村局 88.39%、教育局 87.97% 执行率居前两位,项目开工早、资金支付节奏快。'</li>
      <li style="borderTop:1px dashed #C7C7C7; paddingTop:6px; marginBottom:6px">'预警部门:交通局执行率 82.50% 为五部门最低,低于整体水平 3.27 个百分点,主要受工程招标进度滞后影响。'</li>
      <li style="borderTop:1px dashed #C7C7C7; paddingTop:6px; marginBottom:6px">'下半年建议:对交通局实行项目清单周调度;对执行率已超 87% 的部门,提示避免年末突击支出,确保资金使用合规。'</li>
    </list>
  </div>

  <lineSeparator style="strokeColor:#DCE3EC"></lineSeparator>
  <p style="color:#6c757d; fontSize:8; marginTop:8px">'数据来源:市财政局预算管理一体化系统 | 生成时间:2025年10月8日 | 密级:内部'</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.