Skip to content

Heatmap (deep purple) — generate this PDF with Java (HEATMAP)

JQuick-PdfCreditReport Demo

HEATMAP2 页 A4 · 109 KB

Shows the intensity of metric-by-time intersections as a deep purple heatmap.

Download the PDFView raw template fileBack to all demos

Heatmap (deep purple) — HEATMAP
Rendered output

Output specs

PDF pages
2
Chart type
HEATMAP
Template lines
171
Source lines
81

Java source · JQuickCreditReport10HeatmapTest.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.creditreport;

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;

/**
 * 统一信用报告 —— 风格 10:热力图(深紫)
 *
 * <p>以 {@code report/credit_report_10_heatmap.txt} 为模板,把热力图渲染成 SVG 后
 * 绑定到模板中的 {@code ${svg}} 占位符,输出到 {@code D:\test\creditreport\10_heatmap.pdf}。</p>
 *
 * @author Martin
 * @version 1.0.0
 */
public class JQuickCreditReport10HeatmapTest {

    public static final String path = JQuickConstant.path;

    @Test
    public void report10Heatmap() throws IOException {
        JOption option = new JOption();
        option.title("月度经营热力图", "各业务线月度营收(万元)");
        option.xAxis(new JCategoryAxis().data("1月", "2月", "3月", "4月", "5月", "6月"));
        option.yAxis(new JCategoryAxis().data("软件产品", "技术服务", "云服务", "其他业务"));
        JHeatmap heatmap = new JHeatmap();
        heatmap.data(
                new Object[]{0, 0, 860}, new Object[]{0, 1, 1020}, new Object[]{0, 2, 1180},
                new Object[]{0, 3, 1340}, new Object[]{0, 4, 1520}, new Object[]{0, 5, 1680},
                new Object[]{1, 0, 520}, new Object[]{1, 1, 640}, new Object[]{1, 2, 780},
                new Object[]{1, 3, 890}, new Object[]{1, 4, 1010}, new Object[]{1, 5, 1160},
                new Object[]{2, 0, 380}, new Object[]{2, 1, 460}, new Object[]{2, 2, 540},
                new Object[]{2, 3, 620}, new Object[]{2, 4, 710}, new Object[]{2, 5, 820},
                new Object[]{3, 0, 260}, new Object[]{3, 1, 310}, new Object[]{3, 2, 360},
                new Object[]{3, 3, 420}, new Object[]{3, 4, 470}, new Object[]{3, 5, 540}
        );
        option.series(heatmap);

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

        File dir = new File(path + "creditreport");
        if (!dir.exists()) {
            dir.mkdirs();
        }
        FileOutputStream fileOutputStream = new FileOutputStream(path + "creditreport/10_heatmap.pdf");
        JPdfConfig config = new JPdfConfig();
        // 开启 flex 行布局:图表与其右侧的指标说明面板在宽度允许时并排,而不是换行堆叠。
        config.getLayoutConfig().setFlexLayout(true);
        JQuickPdfFactory factory = new JQuickPdfFactory(config);
        factory.bind("svg", svg);
        byte[] bytes = factory.executeResource("report/credit_report_10_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/credit_report_10_heatmap.txt");

Template file · 10_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="background:linear-gradient(135deg, #311B92 0%, #673AB7 100%); borderRadius:8px; paddings:16px; marginBottom:18px">
    <h1 style="fontSize:21; color:white; textAlignment:center; bold:true; marginBottom:12px">'企业信用评级报告'</h1>
    <div style="display:flex; justifyContent:space-around">
      <div style="width:180px; textAlignment:center">
        <div style="fontSize:8; color:#d1c4e9; textAlignment:center; marginBottom:3px">'报告编号'</div>
        <div style="fontSize:10; color:white; textAlignment:center">'CR-2023-08975'</div>
      </div>
      <div style="width:180px; textAlignment:center">
        <div style="fontSize:8; color:#d1c4e9; textAlignment:center; marginBottom:3px">'评估日期'</div>
        <div style="fontSize:10; color:white; textAlignment:center">'2023年11月15日'</div>
      </div>
      <div style="width:180px; textAlignment:center">
        <div style="fontSize:8; color:#d1c4e9; textAlignment:center; marginBottom:3px">'评估机构'</div>
        <div style="fontSize:10; color:white; textAlignment:center">'四川省企业信用评估中心'</div>
      </div>
    </div>
  </div>

  <div style="marginBottom:18px">
    <h2 style="fontSize:14; color:#311B92; bold:true; marginBottom:10px">'四川省泡海椒科技有限公司'</h2>
    <table style="width:600px; fontSize:10">
      <tr>
        <th style="backgroundColor:#512DA8; color:white; bold:true; padding:6px; textAlignment:left; width:160px">'统一信用代码'</th>
        <td style="padding:6px; textAlignment:left; width:440px">'91110108MA01XX1234'</td>
      </tr>
      <tr>
        <th style="backgroundColor:#ede7f6; color:#311B92; bold:true; padding:6px; textAlignment:left">'成立日期'</th>
        <td style="padding:6px; textAlignment:left">'2018年5月20日'</td>
      </tr>
      <tr>
        <th style="backgroundColor:#ede7f6; color:#311B92; bold:true; padding:6px; textAlignment:left">'注册资本'</th>
        <td style="padding:6px; textAlignment:left">'1000万元人民币'</td>
      </tr>
      <tr>
        <th style="backgroundColor:#ede7f6; color:#311B92; bold:true; padding:6px; textAlignment:left">'法定代表人'</th>
        <td style="padding:6px; textAlignment:left">'泡海椒'</td>
      </tr>
      <tr>
        <th style="backgroundColor:#ede7f6; color:#311B92; bold:true; padding:6px; textAlignment:left">'所属行业'</th>
        <td style="padding:6px; textAlignment:left">'软件和信息技术服务业'</td>
      </tr>
      <tr>
        <th style="backgroundColor:#ede7f6; color:#311B92; bold:true; padding:6px; textAlignment:left">'企业规模'</th>
        <td style="padding:6px; textAlignment:left">'中型(150-200人)'</td>
      </tr>
    </table>
  </div>

  <div style="marginBottom:18px">
    <h2 style="fontSize:13; color:#311B92; bold:true; marginBottom:10px">'历年财务数据(单位:万元)'</h2>
    <table style="width:600px; fontSize:10">
      <tr>
        <th style="backgroundColor:#512DA8; color:white; bold:true; padding:6px; textAlignment:left">'财务指标'</th>
        <th style="backgroundColor:#512DA8; color:white; bold:true; padding:6px; textAlignment:right">'2020年'</th>
        <th style="backgroundColor:#512DA8; color:white; bold:true; padding:6px; textAlignment:right">'2021年'</th>
        <th style="backgroundColor:#512DA8; color:white; bold:true; padding:6px; textAlignment:right">'2022年'</th>
        <th style="backgroundColor:#512DA8; color:white; bold:true; padding:6px; textAlignment:right">'2023年'</th>
        <th style="backgroundColor:#512DA8; color:white; bold:true; padding:6px; textAlignment:right">'增长率'</th>
      </tr>
      <tr>
        <td style="padding:6px; textAlignment:left; borderBottom:1px solid #ede7f6; bold:true">'营业收入'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6">'8,560'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6">'12,340'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6">'18,920'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6">'25,680'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6; color:#512DA8; bold:true">'+44.2%'</td>
      </tr>
      <tr>
        <td style="padding:6px; textAlignment:left; borderBottom:1px solid #ede7f6; bold:true; backgroundColor:#f6f4fb">'净利润'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6; backgroundColor:#f6f4fb">'1,240'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6; backgroundColor:#f6f4fb">'2,150'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6; backgroundColor:#f6f4fb">'3,890'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6; backgroundColor:#f6f4fb">'5,420'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6; backgroundColor:#f6f4fb; color:#512DA8; bold:true">'+63.8%'</td>
      </tr>
      <tr>
        <td style="padding:6px; textAlignment:left; borderBottom:1px solid #ede7f6; bold:true">'总资产'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6">'15,800'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6">'22,450'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6">'31,200'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6">'42,800'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6; color:#512DA8; bold:true">'+39.5%'</td>
      </tr>
      <tr>
        <td style="padding:6px; textAlignment:left; borderBottom:1px solid #ede7f6; bold:true; backgroundColor:#f6f4fb">'净资产'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6; backgroundColor:#f6f4fb">'9,200'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6; backgroundColor:#f6f4fb">'13,800'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6; backgroundColor:#f6f4fb">'19,500'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6; backgroundColor:#f6f4fb">'26,400'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6; backgroundColor:#f6f4fb; color:#512DA8; bold:true">'+42.1%'</td>
      </tr>
      <tr>
        <td style="padding:6px; textAlignment:left; borderBottom:1px solid #ede7f6; bold:true">'毛利率'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6">'42.5%'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6">'45.8%'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6">'48.2%'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6">'51.6%'</td>
        <td style="padding:6px; textAlignment:right; borderBottom:1px solid #ede7f6; color:#512DA8; bold:true">'+9.1%'</td>
      </tr>
    </table>
  </div>

  <div style="marginBottom:18px">
    <h2 style="fontSize:13; color:#311B92; bold:true; marginBottom:10px">'关键经营指标'</h2>
    <div style="display:flex; justifyContent:space-between">
      <div style="width:190px; padding:10px; border:1px solid #673AB7; borderRadius:6px; fontSize:10">
        '营收增长率:连续三年保持40%以上增长,2023年达到25,680万元。'
        '利润率提升:净利率从14.5%提升至21.1%,盈利能力显著增强。'
      </div>
      <div style="width:190px; padding:10px; border:1px solid #673AB7; borderRadius:6px; fontSize:10">
        '研发投入:研发费用年均增长38.9%,占营收比例达13.3%。'
        '人才结构:技术研发人员占比42%,硕士以上学历占35%。'
      </div>
      <div style="width:190px; padding:10px; border:1px solid #673AB7; borderRadius:6px; fontSize:10">
        '客户质量:服务15家上市公司,客户续约率92%,大客户满意度4.8/5.0。'
        '资产质量:资产负债率维持在38%左右,流动比率2.8,偿债能力良好。'
      </div>
    </div>
  </div>

  <div style="marginBottom:18px">
    <h2 style="fontSize:13; color:#311B92; bold:true; textAlignment:center; marginBottom:10px">'月度经营热力图'</h2>
    <div style="textAlignment:center">
      <svg style="width:450px;height:400px">${svg}</svg>
    </div>
    <div style="marginTop:10px">
      <h3 style="fontSize:12; color:#311B92; bold:true; textAlignment:center; marginBottom:8px">'评级指标说明'</h3>
      <div style="display:flex; justifyContent:space-between">
        <div style="width:290px">
          <div style="fontSize:10; marginBottom:6px">
            <span style="color:#512DA8; bold:true">'● 财务状况(90分): '</span>
            '营收稳定增长'
          </div>
          <div style="fontSize:10; marginBottom:6px">
            <span style="color:#2ecc71; bold:true">'● 经营能力(95分): '</span>
            '客户留存率高'
          </div>
        </div>
        <div style="width:290px">
          <div style="fontSize:10; marginBottom:6px">
            <span style="color:#e74c3c; bold:true">'● 偿债能力(85分): '</span>
            '负债率合理'
          </div>
          <div style="fontSize:10; marginBottom:6px">
            <span style="color:#f39c12; bold:true">'● 发展潜力(92分): '</span>
            '研发投入增加'
          </div>
        </div>
      </div>
    </div>
  </div>

  <div style="marginBottom:18px; background:linear-gradient(135deg, #ede7f6 0%, #d1c4e9 100%); borderRadius:10px; padding:16px; borderLeft:4px solid #673AB7">
    <h2 style="fontSize:13; color:#311B92; bold:true; marginBottom:8px">'综合评价'</h2>
    <p style="fontSize:11; textAlignment:left; marginBottom:8px">
      '四川省泡海椒科技有限公司作为国家级高新技术企业和专精特新"小巨人"企业,在云计算和大数据领域表现出色。'
      '公司财务状况健康,经营能力突出,技术创新能力强,具备良好的发展潜力。信用评级为AAA级,展望稳定。'
    </p>
    <p style="fontSize:8; color:#512DA8; textAlignment:right">'认证通过'</p>
  </div>

  <div style="textAlignment:center; marginTop:20px">
    <lineSeparator style="strokeColor:#512DA8"></lineSeparator>
    <p style="fontSize:9; color:#6c757d; textAlignment:center; marginTop:8px">'本报告依据公开信息和专业评估模型生成,仅供参考 | 报告生成时间: 2025年09月06日'</p>
    <p style="fontSize:9; color:#6c757d; textAlignment:center">'© 2023 企业信用评估中心 版权所有 | 认证编号: CE-2023-001'</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.