Java在PowerPoint幻燈片中創(chuàng)建散點(diǎn)圖的方法
散點(diǎn)圖是通過(guò)兩組數(shù)據(jù)構(gòu)成多個(gè)坐標(biāo)點(diǎn),考察坐標(biāo)點(diǎn)的分布,判斷兩變量之間是否存在某種關(guān)聯(lián)或總結(jié)坐標(biāo)點(diǎn)的分布模式。散點(diǎn)圖將序列顯示為一組點(diǎn),值由點(diǎn)在圖表中的位置表示,類(lèi)別由圖表中的不同標(biāo)記表示,通常用于比較跨類(lèi)別的聚合數(shù)據(jù)。本文將為您介如何通過(guò)Java代碼在PowerPoint幻燈片中創(chuàng)建散點(diǎn)圖。以下是我整理的具體方法及思路,并附上Java代碼供大家參考。
代碼編譯環(huán)境:
IntelliJ IDEA 2018(jdk 1.8.0)
Presentation Jar包:Free Spire.Presentation for Java 5.1.0
引入jar包
導(dǎo)入方法1:
手動(dòng)引入。將Free Spire. Presentation for Java下載到本地,解壓,找到lib文件夾下的Spire. Presentation.jar文件。在IDEA中打開(kāi)如下界面,將本地路徑中的jar文件引入Java程序:

導(dǎo)入方法2:如果您想通過(guò) Maven安裝,則可以在 pom.xml 文件中添加以下代碼導(dǎo)入 JAR 文件。
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation.free</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>創(chuàng)建散點(diǎn)圖
下面是創(chuàng)建散點(diǎn)圖的具體方法和步驟:
- 創(chuàng)建 Presentation 類(lèi)的實(shí)例。
- 使用 ShapeCollection.appendChart() 方法將散點(diǎn)圖附加到特定的幻燈片。
- 通過(guò) ChartData.get().setValue() 方法設(shè)置圖表數(shù)據(jù)。
- 使用 IChart 接口提供的方法設(shè)置圖表標(biāo)題、坐標(biāo)軸標(biāo)題、系列標(biāo)簽等。
- 設(shè)置網(wǎng)格線樣式和數(shù)據(jù)點(diǎn)線樣式。
- 使用 Presentation.saveToFile() 方法將文檔保存到指定路徑。
完整代碼
Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideSizeType;
import com.spire.presentation.TextLineStyle;
import com.spire.presentation.charts.ChartType;
import com.spire.presentation.charts.IChart;
import com.spire.presentation.charts.entity.ChartDataLabel;
import com.spire.presentation.drawing.FillFormatType;
import java.awt.*;
import java.awt.geom.Rectangle2D;
public class ScatterChart {
public static void main(String[] args) throws Exception{
//創(chuàng)建Presentation類(lèi)的實(shí)例
Presentation presentation = new Presentation();
presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);
//添加散點(diǎn)圖表到第一張幻燈片
IChart chart = presentation.getSlides().get(0).getShapes().appendChart(ChartType.SCATTER_MARKERS,new Rectangle2D.Float(180, 80, 550, 320),false);
//設(shè)置圖表標(biāo)題
chart.getChartTitle().getTextProperties().setText("散點(diǎn)圖表");
chart.getChartTitle().getTextProperties().isCentered(true);
chart.getChartTitle().setHeight(20f);
chart.hasTitle(true);
//設(shè)置圖表數(shù)據(jù)源
Double[] xData = new Double[] { 1.0, 3.4, 5.0, 7.9 };
Double[] yData = new Double[] { 4.3, 13.2, 7.7, 6.0 };
chart.getChartData().get(0,0).setText("X-值");
chart.getChartData().get(0,1).setText("Y-值");
for (int i = 0; i < xData.length; i++) {
chart.getChartData().get(i+1,0).setValue(xData[i]);
chart.getChartData().get(i+1,1).setValue(yData[i]);
}
//設(shè)置系列標(biāo)簽
chart.getSeries().setSeriesLabel(chart.getChartData().get("B1","B1"));
//設(shè)置X和Y軸值
chart.getSeries().get(0).setXValues(chart.getChartData().get("A2","A5"));
chart.getSeries().get(0).setYValues(chart.getChartData().get("B2","B5"));
//添加數(shù)據(jù)標(biāo)簽
for (int i = 0; i < 4; i++)
{
ChartDataLabel dataLabel = chart.getSeries().get(0).getDataLabels().add();
dataLabel.setLabelValueVisible(true);
}
//設(shè)置主軸標(biāo)題和次軸標(biāo)題
chart.getPrimaryValueAxis().hasTitle(true);
chart.getPrimaryValueAxis().getTitle().getTextProperties().setText("X-軸 標(biāo)題");
chart.getSecondaryValueAxis().hasTitle(true);
chart.getSecondaryValueAxis().getTitle().getTextProperties().setText("Y-軸 標(biāo)題");
//設(shè)置網(wǎng)格線
chart.getSecondaryValueAxis().getMajorGridTextLines().setFillType(FillFormatType.SOLID);
chart.getSecondaryValueAxis().getMajorGridTextLines().setStyle(TextLineStyle.THIN_THIN);
chart.getSecondaryValueAxis().getMajorGridTextLines().getSolidFillColor().setColor(Color.GRAY);
chart.getPrimaryValueAxis().getMajorGridTextLines().setFillType(FillFormatType.NONE);
//設(shè)置數(shù)據(jù)點(diǎn)線
chart.getSeries().get(0).getLine().setFillType(FillFormatType.SOLID);
chart.getSeries().get(0).getLine().setWidth(0.1f);
chart.getSeries().get(0).getLine().getSolidFillColor().setColor(Color.GREEN);
//保存文檔
presentation.saveToFile("ScatterChart.pptx", FileFormat.PPTX_2013);
presentation.dispose();
}
}效果圖

到此這篇關(guān)于Java如何在PowerPoint幻燈片中創(chuàng)建散點(diǎn)圖的文章就介紹到這了,更多相關(guān)Java PowerPoint幻燈片散點(diǎn)圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
利用idea快速搭建一個(gè)spring-cloud(圖文)
本文主要介紹了idea快速搭建一個(gè)spring-cloud,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07
hadoop運(yùn)行java程序(jar包)并運(yùn)行時(shí)動(dòng)態(tài)指定參數(shù)
這篇文章主要介紹了hadoop如何運(yùn)行java程序(jar包)并運(yùn)行時(shí)動(dòng)態(tài)指定參數(shù),使用hadoop 運(yùn)行 java jar包,Main函數(shù)一定要加上全限定類(lèi)名,需要的朋友可以參考下2021-06-06
解決springboot項(xiàng)目不配置數(shù)據(jù)源啟動(dòng)報(bào)錯(cuò)問(wèn)題
這篇文章主要介紹了解決springboot項(xiàng)目不配置數(shù)據(jù)源啟動(dòng)報(bào)錯(cuò)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-12-12
Mybatis -如何處理clob類(lèi)型數(shù)據(jù)
這篇文章主要介紹了Mybatis 如何處理clob類(lèi)型數(shù)據(jù)的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06
MyBatis實(shí)現(xiàn)批量插入數(shù)據(jù),多重forEach循環(huán)
這篇文章主要介紹了MyBatis實(shí)現(xiàn)批量插入數(shù)據(jù),多重forEach循環(huán)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02
基于SpringBoot和Vue實(shí)現(xiàn)分片上傳系統(tǒng)
最近想做一個(gè)關(guān)于文件上傳的個(gè)人小網(wǎng)盤(pán),一開(kāi)始嘗試使用了OSS的方案,但是該方案對(duì)于大文件來(lái)說(shuō)并不友好,所以開(kāi)始嘗試分片上傳方案的探索,接下來(lái)小編給大家詳細(xì)的介紹一下如何基于SpringBoot和Vue實(shí)現(xiàn)分片上傳系統(tǒng),需要的朋友可以參考下2023-12-12

