Skip to content

API call volume trend (government cloud operations) — generate this PDF with Java (MultipleLine)

JQuick-PdfBiz Demo

MultipleLine2 页 A4 · 357 KB

Tracks daily call volume per interface with multiple line series to compare traffic across services.

Download the PDFView raw template fileBack to all demos

API call volume trend (government cloud operations) — MultipleLine
Rendered output

Output specs

PDF pages
2
Chart type
MultipleLine
Template lines
65
Source lines
132

Java source · JQuickBiz43ApiCallsLineTest.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.JTitle;
import com.github.paohaijiao.combol.JMultiLineChartData;
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;
import java.util.List;

/**
 * 业务场景 Demo 43:系统接口调用量趋势(政务云平台运维)
 *
 * <p>业务场景:政务云平台 API 网关按月统计身份核验、数据查询、证照下载、电子签章四类核心接口的
 * 成功调用量,用于平台容量规划与限流策略制定,主色采用深蓝 #0D47A1。</p>
 * <p>实际图表类型:{@link JChartType#MultipleLine} 多重折线图(四条接口调用量共用「万次」量纲,观察月度增长与峰值)。</p>
 *
 * <p>模板:{@code report/biz/43_api_calls_line.txt};图表以 SVG 文本形式绑定到模板的
 * {@code ${svg}} 占位符,输出到 {@code D:\test\biz\43_api_calls_line.pdf}。</p>
 *
 * <p>图表尺寸说明:图表按 700pt × 380pt(宽 × 高)的横版比例设计;模板中 {@code <svg>}
 * 只声明宽度、不声明高度,因此宽度被页面自动收窄时高度会按原比例同步缩放,不会纵向拉伸变形。</p>
 *
 * @author Martin
 * @version 1.0.0
 */
public class JQuickBiz43ApiCallsLineTest {

    public static final String path = JQuickConstant.path;

    @Test
    public void biz43ApiCallsLine() throws IOException {
        List<String> months = Arrays.asList("1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月");
        JMultiLineChartData chartData = new JMultiLineChartData();
        chartData.setXAxisLabels(months);
        chartData.setTitleText("2024年平台接口调用量趋势");
        chartData.setSubtitleText("四类核心接口月度调用量对比");
        chartData.setYAxisTitle("调用量(万次)");
        chartData.setFooterText("数据来源:政务云API网关 | 统计口径:自然月(单位:万次)");
        chartData.setGridCount(6);
        chartData.setShowDataLabels(false);
        chartData.setShowInnerPoint(true);
        chartData.setPointRadius(5);
        chartData.setInnerPointRadius(2);
        chartData.setChartAreaColor(new Color(248, 249, 250));
        chartData.setAxisColor(Color.BLACK);
        chartData.setGridColor(new Color(220, 220, 220));
        chartData.setTextColor(Color.BLACK);
        chartData.setFooterColor(new Color(128, 128, 128));
        chartData.setValueWithPercent(false);
        chartData.setAutoCalculateMax(true);
        chartData.setRotateXAxisLabels(false);
        // 身份核验:平台最大流量入口
        JMultiLineChartData.LineData lineA = new JMultiLineChartData.LineData();
        lineA.setName("身份核验");
        lineA.setLegendText("身份核验(万次)");
        lineA.setValues(Arrays.asList(1280.0, 1245.0, 1360.0, 1420.0, 1385.0, 1450.0, 1520.0, 1495.0, 1560.0, 1620.0, 1685.0, 1740.0));
        lineA.setLineColor(new Color(13, 71, 161));
        lineA.setLineWidth(2.5f);
        // 数据查询:共享交换与数据核验调用
        JMultiLineChartData.LineData lineB = new JMultiLineChartData.LineData();
        lineB.setName("数据查询");
        lineB.setLegendText("数据查询(万次)");
        lineB.setValues(Arrays.asList(860.0, 835.0, 905.0, 960.0, 940.0, 985.0, 1030.0, 1015.0, 1065.0, 1120.0, 1160.0, 1205.0));
        lineB.setLineColor(new Color(21, 101, 192));
        lineB.setLineWidth(2.5f);
        // 证照下载:电子证照库对外服务
        JMultiLineChartData.LineData lineC = new JMultiLineChartData.LineData();
        lineC.setName("证照下载");
        lineC.setLegendText("证照下载(万次)");
        lineC.setValues(Arrays.asList(420.0, 402.0, 445.0, 478.0, 462.0, 495.0, 520.0, 508.0, 536.0, 560.0, 585.0, 612.0));
        lineC.setLineColor(new Color(0, 131, 143));
        lineC.setLineWidth(2.5f);
        // 电子签章:增速最快的新增能力
        JMultiLineChartData.LineData lineD = new JMultiLineChartData.LineData();
        lineD.setName("电子签章");
        lineD.setLegendText("电子签章(万次)");
        lineD.setValues(Arrays.asList(210.0, 226.0, 248.0, 265.0, 288.0, 305.0, 326.0, 348.0, 372.0, 395.0, 418.0, 442.0));
        lineD.setLineColor(new Color(120, 144, 156));
        lineD.setLineWidth(2.5f);
        chartData.setLineDataList(Arrays.asList(lineA, lineB, lineC, lineD));
        // 设置完折线数据后必须刷新 Y 轴最大值
        chartData.updateMaxValues();
        JOption option = new JOption();
        JTitle title = new JTitle();
        title.setText("2024年平台接口调用量趋势");
        title.setSubtext("四类核心接口月度调用量对比");
        option.setTitle(title);
        option.setData(chartData);

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

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

Template file · 43_api_calls_line.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="marginBottom:10px; padding:10px; backgroundColor:#E9F0FA; borderTop:3px solid #0D47A1; borderRadius:4px">
    <h2 style="color:#0D47A1; marginTop:0; marginBottom:6px; fontSize:15; bold:true; textAlignment:center">'一、核心接口调用量走势'</h2>
    <p style="fontSize:9; color:#6c757d; textAlignment:center; marginBottom:6px">'统计周期:2024年1月 - 2024年12月 | 数据来源:政务云API网关调用日志(单位:万次)'</p>
    <div style="display:flex; justifyContent:center">
      <svg style="width:700pt">${svg}</svg>
    </div>
  </div>

  <h2 style="color:#0D47A1; fontSize:13; bold:true; underline:true; marginBottom:6px">'二、四类接口全年调用量汇总'</h2>
  <table style="width:560px; fontSize:10">
    <tr>
      <th style="backgroundColor:#0D47A1; color:white; padding:6px; textAlign:center; border:1px solid #DCE3EC">'接口名称'</th>
      <th style="backgroundColor:#0D47A1; color:white; padding:6px; textAlign:center; border:1px solid #DCE3EC">'全年调用量(万次)'</th>
      <th style="backgroundColor:#0D47A1; color:white; padding:6px; textAlign:center; border:1px solid #DCE3EC">'同比增幅'</th>
      <th style="backgroundColor:#0D47A1; 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">'17,760'</td>
      <td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'+18.6%'</td>
      <td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'12月(1,740)'</td>
    </tr>
    <tr>
      <td style="padding:5px; backgroundColor:#E9F0FA; border:1px solid #DCE3EC">'数据查询'</td>
      <td style="padding:5px; textAlign:right; backgroundColor:#E9F0FA; border:1px solid #DCE3EC">'12,080'</td>
      <td style="padding:5px; textAlign:right; backgroundColor:#E9F0FA; border:1px solid #DCE3EC">'+22.4%'</td>
      <td style="padding:5px; textAlign:right; backgroundColor:#E9F0FA; border:1px solid #DCE3EC">'12月(1,205)'</td>
    </tr>
    <tr>
      <td style="padding:5px; border:1px solid #DCE3EC">'证照下载'</td>
      <td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'6,023'</td>
      <td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'+31.2%'</td>
      <td style="padding:5px; textAlign:right; border:1px solid #DCE3EC">'12月(612)'</td>
    </tr>
    <tr>
      <td style="padding:5px; backgroundColor:#E9F0FA; border:1px solid #DCE3EC">'电子签章'</td>
      <td style="padding:5px; textAlign:right; backgroundColor:#E9F0FA; border:1px solid #DCE3EC">'3,843'</td>
      <td style="padding:5px; textAlign:right; backgroundColor:#E9F0FA; border:1px solid #DCE3EC">'+56.8%'</td>
      <td style="padding:5px; textAlign:right; backgroundColor:#E9F0FA; border:1px solid #DCE3EC">'12月(442)'</td>
    </tr>
    <tr>
      <td style="padding:6px; backgroundColor:#0D47A1; color:white; bold:true; border:1px solid #0D47A1">'四类合计'</td>
      <td style="padding:6px; textAlign:right; backgroundColor:#0D47A1; color:white; bold:true; border:1px solid #0D47A1">'39,706'</td>
      <td style="padding:6px; textAlign:right; backgroundColor:#0D47A1; color:white; bold:true; border:1px solid #0D47A1">'+24.1%'</td>
      <td style="padding:6px; textAlign:right; backgroundColor:#0D47A1; color:white; bold:true; border:1px solid #0D47A1">'12月(3,999)'</td>
    </tr>
  </table>

  <h2 style="color:#0D47A1; fontSize:13; bold:true; underline:true; marginBottom:6px; marginTop:10px">'三、调用结构与容量研判'</h2>
  <list style="list-style-type:none; padding-left:0; fontSize:10">
    <li style="borderTop:1px dashed #C7C7C7; paddingTop:6px; marginBottom:4px">'全年四类接口调用总量 39,706 万次(约 3.97 亿次),同比增长 24.1%,四季度为全年调用高峰。'</li>
    <li style="borderTop:1px dashed #C7C7C7; paddingTop:6px; marginBottom:4px">'电子签章同比增幅 56.8% 为四类最高,证照下载 31.2% 次之,反映「全程网办」事项扩容与电子证照复用率提升。'</li>
    <li style="borderTop:1px dashed #C7C7C7; paddingTop:6px; marginBottom:4px">'身份核验全年 17,760 万次、占全部调用量的 44.7%,是平台最主要流量入口,建议单独制定限流策略与容量冗余。'</li>
    <li style="borderTop:1px dashed #C7C7C7; paddingTop:6px; marginBottom:4px">'2月为全年唯一环比下滑月份,受春节假期业务量回落影响;3月起快速恢复并重回上行通道,12月单月 3,999 万次创年内新高。'</li>
  </list>

  <div style="textAlignment:center; marginTop:10px; paddingTop:10px; borderTop:1px solid #dee2e6; color:#6c757d; fontSize:8">
    <p>'数据来源:政务云API网关调用日志 | 生成时间:2024年12月31日'</p>
    <p>'内部资料 · 未经许可请勿外传'</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.