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

方法2:通過maven倉庫安裝導(dǎo)入。可參考導(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è)置圖表名稱
chart.getChartTitle().getTextProperties().setText("上半年銷量");
chart.getChartTitle().getTextProperties().isCentered(true);
chart.getChartTitle().setHeight(30);
chart.hasTitle(true);
//寫入圖表數(shù)據(jù)
chart.getChartData().get(0,0).setText("月份");
chart.getChartData().get(0,1).setText("銷量");
chart.getChartData().get(0,2).setText("環(huán)比增長(%)");
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ù)來源
chart.getSeries().setSeriesLabel(chart.getChartData().get("B1", "C1"));
//設(shè)置分類標(biāo)簽數(shù)據(jù)來源
chart.getCategories().setCategoryLabels(chart.getChartData().get("A2", "A7"));
//設(shè)置系列的數(shù)據(jù)來源
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的圖表類型設(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è)置分類間距
chart.setGapDepth(200);
//保存文檔
presentation.saveToFile("chart.pptx", FileFormat.PPTX_2013);
presentation.dispose();
}
}
圖表添加效果:

以上就是本文的全部內(nèi)容,希望對大家的學(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幻燈片過程解析
- Java如何在PPT中繪制圖形
- 淺談Java設(shè)置PPT幻燈片背景——純色、漸變、圖片背景
- Java使用jacob將微軟office中word、excel、ppt轉(zhuǎn)成pdf
- Java 給PPT添加動(dòng)畫效果的示例
相關(guān)文章
feign遠(yuǎn)程調(diào)用無法傳遞對象屬性405的問題
這篇文章主要介紹了feign遠(yuǎn)程調(diào)用無法傳遞對象屬性405的問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03
Java中防止數(shù)據(jù)重復(fù)提交超簡單的6種方法
在平時(shí)開發(fā)中,如果網(wǎng)速比較慢的情況下,用戶提交表單后,發(fā)現(xiàn)服務(wù)器半天都沒有響應(yīng),那么用戶可能會(huì)以為是自己沒有提交表單,就會(huì)再點(diǎn)擊提交按鈕重復(fù)提交表單,這篇文章主要給大家介紹了關(guān)于Java中防止數(shù)據(jù)重復(fù)提交超簡單的6種方法,需要的朋友可以參考下2021-11-11
SpringBoot項(xiàng)目整合jasypt實(shí)現(xiàn)過程詳解
這篇文章主要介紹了SpringBoot項(xiàng)目整合jasypt實(shí)現(xiàn)過程詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08
Java語言實(shí)現(xiàn)簡單FTP軟件 FTP連接管理模塊實(shí)現(xiàn)(8)
這篇文章主要為大家詳細(xì)介紹了Java語言實(shí)現(xiàn)簡單FTP軟件,F(xiàn)TP連接管理模塊的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04

