Skip to content

Monthly revenue trends of three business segments (business analysis) — generate this PDF with Java (MultipleLine)

JQuick-PdfBiz Demo

MultipleLine1 页 A4 · 305 KB

A multi-line chart of 2024 monthly revenue for software, hardware and services, concluding that software stayed steady, hardware dipped on supply-chain pressure and services grew the fastest.

Download the PDFView raw template fileBack to all demos

Monthly revenue trends of three business segments (business analysis) — MultipleLine
Rendered output

Output specs

PDF pages
1
Chart type
MultipleLine
Template lines
36
Source lines
111

Java source · JQuickBiz65MultipleLineTest.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.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 65:三大业务板块月度营收走势(经营分析)
 *
 * <p>业务场景:经营分析部门以多重折线图展示软件、硬件、服务三条业务线
 * 2024 年逐月营收变化趋势。</p>
 * <p>实际图表类型:{@link JChartType#MultipleLine} 多重折线图。</p>
 *
 * <p>模板:{@code report/biz/65_multipleLine.txt};图表以 SVG 文本形式绑定到模板的
 * {@code ${svg}} 占位符,输出到 {@code D:\test\biz\65_multipleLine.pdf}。</p>
 *
 * <p>图表尺寸说明:图表按 700pt 宽的横版比例设计;模板中 {@code <svg>}
 * 只声明宽度、不声明高度,宽度被页面自动收窄时高度会按原比例同步缩放。</p>
 *
 * @author Martin
 * @version 1.0.0
 */
public class JQuickBiz65MultipleLineTest {

    public static final String path = JQuickConstant.path;

    @Test
    public void biz65MultipleLine() throws IOException {
        List<String> months = Arrays.asList("1月", "2月", "3月", "4月", "5月", "6月",
                "7月", "8月", "9月", "10月", "11月", "12月");

        JMultiLineChartData chartData = new JMultiLineChartData();
        chartData.setTitleText("三大业务板块月度营收走势");
        chartData.setSubtitleText("软件 / 硬件 / 服务  2024 年逐月营收(万元)");
        chartData.setXAxisLabels(months);
        chartData.setYAxisTitle("营收(万元)");
        chartData.setFooterText("数据来源:经营分析系统");
        chartData.setGridCount(6);
        chartData.setShowDataLabels(false);

        JMultiLineChartData.LineData software = new JMultiLineChartData.LineData();
        software.setName("软件");
        software.setLegendText("软件业务");
        software.setValues(Arrays.asList(320.0, 335.0, 350.0, 368.0, 385.0, 402.0, 420.0, 438.0, 455.0, 472.0, 490.0, 510.0));
        software.setLineColor(new Color(0, 96, 100));
        software.setLineWidth(2.5f);

        JMultiLineChartData.LineData hardware = new JMultiLineChartData.LineData();
        hardware.setName("硬件");
        hardware.setLegendText("硬件业务");
        hardware.setValues(Arrays.asList(420.0, 410.0, 435.0, 390.0, 405.0, 425.0, 440.0, 430.0, 450.0, 460.0, 475.0, 485.0));
        hardware.setLineColor(new Color(38, 166, 154));
        hardware.setLineWidth(2.5f);

        JMultiLineChartData.LineData service = new JMultiLineChartData.LineData();
        service.setName("服务");
        service.setLegendText("服务业务");
        service.setValues(Arrays.asList(180.0, 195.0, 210.0, 228.0, 245.0, 262.0, 280.0, 300.0, 322.0, 345.0, 368.0, 392.0));
        service.setLineColor(new Color(77, 182, 172));
        service.setLineWidth(2.5f);

        chartData.setLineDataList(Arrays.asList(software, hardware, service));
        chartData.updateMaxValues();

        JOption option = new JOption();
        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/65_multipleLine.pdf");
        JPdfConfig config = new JPdfConfig();
        config.getLayoutConfig().setFlexLayout(true);
        JQuickPdfFactory factory = new JQuickPdfFactory(config);
        factory.bind("svg", svg);
        byte[] bytes = factory.executeResource("report/biz/65_multipleLine.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/65_multipleLine.txt");

Template file · 65_multipleLine.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>
  // 65 多重折线图 Demo:多个系列以折线形式叠加展示同一时间维度的变化趋势
  <div style="background:#006064; 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:#B2EBF2; fontSize:9">'软件 / 硬件 / 服务 三条业务线,2024 年逐月营收对比'</p>
      </div>
      <div style="width:220px; textAlignment:right; borderLeft:1px solid #4DD0E1; paddingLeft:10px">
        <p style="color:white; fontSize:9">'统计周期:2024 年 1-12 月'</p>
        <p style="color:#B2EBF2; fontSize:9">'单位:万元'</p>
        <p style="color:#B2EBF2; fontSize:9">'编制:经营分析部'</p>
      </div>
    </div>
  </div>

  <div style="marginBottom:10px; padding:10px; backgroundColor:#F7F9FC; borderRadius:4px; borderTop:2px solid #006064">
    <h2 style="color:#006064; 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:#006064">'软件业务稳健增长:'</span>'全年保持稳定上升态势,12 月达到峰值。'</li>
    <li style="marginBottom:6px"><span style="bold:true; color:#006064">'硬件业务波动较大:'</span>'受供应链影响,Q2 出现阶段性回落。'</li>
    <li style="marginBottom:6px"><span style="bold:true; color:#006064">'服务业务增速最快:'</span>'同比增幅超过 30%,成为新的增长引擎。'</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.