跳转到内容

Java 生成「城市综合发展评估折线雷达图(发改研究)」PDF 示例(LineRadar)

JQuick-PdfBiz Demo

LineRadar1 页 A4 · 301 KB

城市季度 GDP 增速折线叠加八维发展指数散点:创新、协调、绿色、开放、共享等维度同时呈现在一张图上,图下给出绿色指数突出与创新维度待提升的结论。

下载 PDF 文件查看模板原始文件返回全部示例

城市综合发展评估折线雷达图(发改研究) — LineRadar
渲染效果

输出规格

PDF 页数
1
图表类型
LineRadar
模板行数
36
源码行数
93

Java 源码 · JQuickBiz61LineRadarTest.java

以下代码即生成上方 PDF 的完整测试类,可直接复制运行;Maven 依赖见快速开始章节。

/*
 * 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.JLineScatterChartData;
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 61:城市综合发展评估折线雷达图(发改研究)
 *
 * <p>业务场景:发改研究院以折线展示季度 GDP 走势,以雷达散点展示创新、协调、
 * 绿色、开放、共享五维发展指数得分,综合评估城市发展质量。</p>
 * <p>实际图表类型:{@link JChartType#LineRadar} 折线雷达混合图。</p>
 *
 * <p>模板:{@code report/biz/61_lineRadar.txt};图表以 SVG 文本形式绑定到模板的
 * {@code ${svg}} 占位符,输出到 {@code D:\test\biz\61_lineRadar.pdf}。</p>
 *
 * <p>图表尺寸说明:图表按 700pt 宽的横版比例设计;模板中 {@code <svg>}
 * 只声明宽度、不声明高度,宽度被页面自动收窄时高度会按原比例同步缩放。</p>
 *
 * @author Martin
 * @version 1.0.0
 */
public class JQuickBiz61LineRadarTest {

    public static final String path = JQuickConstant.path;

    @Test
    public void biz61LineRadar() throws IOException {
        List<String> categories = Arrays.asList("创新", "协调", "绿色", "开放", "共享", "安全", "包容", "高效");
        // 折线:各季度 GDP 增速(%)
        List<Double> lineValues = Arrays.asList(5.2, 5.5, 5.8, 5.6, 6.0, 6.2, 5.9, 6.3);
        // 雷达散点:各维度发展指数得分(满分 100)
        List<Double> scatterValues = Arrays.asList(78.0, 72.0, 88.0, 65.0, 80.0, 70.0, 76.0, 74.0);

        JLineScatterChartData data = new JLineScatterChartData();
        data.setTitleText("城市综合发展评估折线雷达图");
        data.setSubtitleText("折线:季度 GDP 增速(%) 雷达散点:八维发展指数得分");
        data.setFooterText("数据来源:统计公报与专项评估");
        data.setCategories(categories);
        data.setLineValues(lineValues);
        data.setScatterValues(scatterValues);
        data.setLineSeriesName("GDP 增速");
        data.setScatterSeriesName("发展指数");
        data.setMaxValue(100);
        data.setGridCount(5);
        data.setShowDataLabels(true);

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

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

        File dir = new File(path + "biz");
        if (!dir.exists()) {
            dir.mkdirs();
        }
        FileOutputStream fileOutputStream = new FileOutputStream(path + "biz/61_lineRadar.pdf");
        JPdfConfig config = new JPdfConfig();
        config.getLayoutConfig().setFlexLayout(true);
        JQuickPdfFactory factory = new JQuickPdfFactory(config);
        factory.bind("svg", svg);
        byte[] bytes = factory.executeResource("report/biz/61_lineRadar.txt");
        fileOutputStream.write(bytes);
        fileOutputStream.close();
    }
}

最小调用(3 行)

不想读完整测试类?核心就是这三行:绑定图表 SVG,执行模板,拿到 PDF 字节流。可直接复制到你的项目里。

// config 可省略;svg 来自 JChartRendererFactory.renderChart(...),见下方完整源码
factory.bind("svg", svg);
byte[] pdf = new JQuickPdfFactory(config).executeResource("report/biz/61_lineRadar.txt");

模板文件 · 61_lineRadar.txt

类 HTML + 内联 CSS 的模板语法,绑定数据后渲染为 PDF。下方为完整模板,可直接复制,也可下载原始文件。

<pdf>
<body>
  // 61 折线雷达混合图 Demo:折线展示时间序列趋势,雷达展示多维度能力分布
  <div style="background:#00695C; 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:#B2DFDB; fontSize:9">'折线:GDP 季度走势 雷达:五维发展指数得分'</p>
      </div>
      <div style="width:220px; textAlignment:right; borderLeft:1px solid #4DB6AC; paddingLeft:10px">
        <p style="color:white; fontSize:9">'统计年度:2024 年'</p>
        <p style="color:#B2DFDB; fontSize:9">'评估对象:某市'</p>
        <p style="color:#B2DFDB; fontSize:9">'编制:发改研究院'</p>
      </div>
    </div>
  </div>

  <div style="marginBottom:10px; padding:10px; backgroundColor:#F7F9FC; borderRadius:4px; borderTop:2px solid #00695C">
    <h2 style="color:#00695C; marginBottom:6px; fontSize:13; bold:true">'一、季度 GDP 走势与五维发展指数'</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  折线雷达混合图:折线反映季度 GDP 增速,雷达散点反映创新、协调、绿色、开放、共享五维得分'</p>
  </div>

  <list style="listStyleType:disc; paddingLeft:16px; fontSize:10">
    <li style="marginBottom:6px"><span style="bold:true; color:#00695C">'经济稳步增长:'</span>'四个季度 GDP 增速保持在合理区间,四季度小幅回升。'</li>
    <li style="marginBottom:6px"><span style="bold:true; color:#00695C">'绿色指数突出:'</span>'五维中绿色发展得分最高,生态环境治理成效显著。'</li>
    <li style="marginBottom:6px"><span style="bold:true; color:#00695C">'建议:'</span>'创新维度仍有提升空间,建议加大研发投入与人才引进力度。'</li>
  </list>

  <lineSeparator style="strokeColor:#DCE3EC"></lineSeparator>
  <p style="color:#6c757d; fontSize:8; textAlignment:center; marginTop:6px">'生成时间:2025年1月6日 | 批准人:研究院院长'</p>
</body>
</pdf>

同分组示例

本页 PDF、预览图、模板与源码均由 JQuick-Pdf 真实运行产出,可自由复制到你的项目中使用。