Java 在PPT中添加混合圖表過(guò)程詳解
本文將介紹通過(guò)Java程序在PPT幻燈片中添加混合圖表的方法,即,將不同類(lèi)型的圖表類(lèi)型放置在同一圖表中,用于展示同一時(shí)期或階段的數(shù)據(jù)在不同參數(shù)標(biāo)準(zhǔn)下的變化情況,便于對(duì)數(shù)據(jù)的綜合分析。
使用工具:Free Spire.Presentation for Java(免費(fèi)版)
Jar文件獲取及導(dǎo)入:
方法1:通過(guò)官網(wǎng)下載jar文件包。下載后,解壓文件,并將lib文件夾下的Spire.Presentation.jar導(dǎo)入java程序。參考如下導(dǎo)入效果:

方法2:通過(guò)maven倉(cāng)庫(kù)安裝導(dǎo)入??蓞⒖?a target="_blank" href="http://www.dbjr.com.cn/article/164716.htm">導(dǎo)入方法。
Java代碼示例(供參考)
import com.spire.presentation.*;
import com.spire.presentation.charts.ChartType;
import com.spire.presentation.charts.IChart;
import com.spire.presentation.drawing.FillFormatType;
import java.awt.geom.Rectangle2D;
public class Chart {
public static void main(String[] args) throws Exception{
//創(chuàng)建PowerPoint文檔
Presentation presentation = new Presentation();
//添加一個(gè)柱狀圖
Rectangle2D.Double rect = new Rectangle2D.Double(60, 100, 600, 350);
IChart chart = presentation.getSlides().get(0).getShapes().appendChart(ChartType.COLUMN_CLUSTERED, rect);
//設(shè)置圖表名稱(chēng)
chart.getChartTitle().getTextProperties().setText("上半年銷(xiāo)量");
chart.getChartTitle().getTextProperties().isCentered(true);
chart.getChartTitle().setHeight(30);
chart.hasTitle(true);
//寫(xiě)入圖表數(shù)據(jù)
chart.getChartData().get(0,0).setText("月份");
chart.getChartData().get(0,1).setText("銷(xiāo)量");
chart.getChartData().get(0,2).setText("環(huán)比增長(zhǎng)(%)");
chart.getChartData().get(1,0).setText("1月");
chart.getChartData().get(1,1).setNumberValue(120);
chart.getChartData().get(1,2).setNumberValue(12);
chart.getChartData().get(2,0).setText("2月");
chart.getChartData().get(2,1).setNumberValue(100);
chart.getChartData().get(2,2).setNumberValue(10);
chart.getChartData().get(3,0).setText("3月");
chart.getChartData().get(3,1).setNumberValue(80);
chart.getChartData().get(3,2).setNumberValue(9);
chart.getChartData().get(4,0).setText("4月");
chart.getChartData().get(4,1).setNumberValue(120);
chart.getChartData().get(4,2).setNumberValue(15);
chart.getChartData().get(5,0).setText("5月");
chart.getChartData().get(5,1).setNumberValue(90);
chart.getChartData().get(5,2).setNumberValue(11);
chart.getChartData().get(6,0).setText("6月");
chart.getChartData().get(6,1).setNumberValue(110);
chart.getChartData().get(6,2).setNumberValue(10.5);
//設(shè)置系列標(biāo)簽數(shù)據(jù)來(lái)源
chart.getSeries().setSeriesLabel(chart.getChartData().get("B1", "C1"));
//設(shè)置分類(lèi)標(biāo)簽數(shù)據(jù)來(lái)源
chart.getCategories().setCategoryLabels(chart.getChartData().get("A2", "A7"));
//設(shè)置系列的數(shù)據(jù)來(lái)源
chart.getSeries().get(0).setValues(chart.getChartData().get("B2", "B7"));
chart.getSeries().get(1).setValues(chart.getChartData().get("C2", "C7"));
chart.getSeries().get(1).getDataLabels().setLabelValueVisible(true);//設(shè)置顯示系列2的數(shù)據(jù)標(biāo)簽值
chart.getSeries().get(1).setType(ChartType.LINE_MARKERS);//將系列2的圖表類(lèi)型設(shè)置為折線圖
chart.getSeries().get(1).setUseSecondAxis(true);//將系列2繪制在次坐標(biāo)軸
chart.getSecondaryValueAxis().getMajorGridTextLines().setFillType(FillFormatType.NONE);//不顯示次坐標(biāo)軸的網(wǎng)格線
//設(shè)置系列重疊
chart.setOverLap(-30);
//設(shè)置分類(lèi)間距
chart.setGapDepth(200);
//保存文檔
presentation.saveToFile("chart.pptx", FileFormat.PPTX_2013);
presentation.dispose();
}
}
圖表添加效果:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Java如何為 PPT 中的圖形添加陰影效果
- Java 創(chuàng)建并應(yīng)用PPT幻燈片母版的方法示例
- Java 在PPT中添加文本和圖片超鏈接的實(shí)現(xiàn)方法
- java實(shí)現(xiàn)在線預(yù)覽--poi實(shí)現(xiàn)word、excel、ppt轉(zhuǎn)html的方法
- Java 添加文本框到PPT幻燈片過(guò)程解析
- Java如何在PPT中繪制圖形
- 淺談Java設(shè)置PPT幻燈片背景——純色、漸變、圖片背景
- Java使用jacob將微軟office中word、excel、ppt轉(zhuǎn)成pdf
- Java 給PPT添加動(dòng)畫(huà)效果的示例
相關(guān)文章
基于Java Socket實(shí)現(xiàn)一個(gè)簡(jiǎn)易在線聊天功能(一)
這篇文章主要給大家介紹基于Java Socket實(shí)現(xiàn)一個(gè)簡(jiǎn)易在線聊天功能(一),分為客戶(hù)端和服務(wù)端兩段代碼,非常具有參考價(jià)值,感興趣的朋友一起學(xué)習(xí)吧2016-05-05
Springboot2.7+Minio8 實(shí)現(xiàn)大文件分片上傳
本文主要介紹了Springboot2.7+Minio8 實(shí)現(xiàn)大文件分片上傳,通過(guò)文件切片上傳,我們能夠提高文件上傳的速度,優(yōu)化用戶(hù)體驗(yàn),具有一定的參考價(jià)值,感興趣的可以了解一下2023-12-12
JavaCV使用ffmpeg實(shí)現(xiàn)錄屏功能
這篇文章主要介紹了JavaCV如何使用ffmpeg實(shí)現(xiàn)錄屏功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-06-06
Spring?BOOT?AOP基礎(chǔ)應(yīng)用教程
這篇文章主要介紹了Spring?BOOT?AOP的使用,文章從相關(guān)問(wèn)題展開(kāi)全文內(nèi)容詳情,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-07-07
Spring Security Remember me使用及原理詳解
這篇文章主要介紹了Spring Security Remember me使用及原理詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09
解決異常處理問(wèn)題:getReader()?has?already?been?called?for?this
這篇文章主要介紹了解決異常處理:getReader()?has?already?been?called?for?this問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01
基于jstree使用JSON數(shù)據(jù)組裝成樹(shù)
這篇文章主要為大家詳細(xì)介紹了基于jstree使用JSON數(shù)據(jù)組裝成樹(shù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08
非常實(shí)用的java自動(dòng)答題計(jì)時(shí)計(jì)分器
這篇文章主要為大家詳細(xì)介紹了非常實(shí)用的java自動(dòng)答題計(jì)時(shí)計(jì)分器的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01

