Java 在PPT中添加混合圖表過程詳解
本文將介紹通過Java程序在PPT幻燈片中添加混合圖表的方法,即,將不同類型的圖表類型放置在同一圖表中,用于展示同一時期或階段的數(shù)據(jù)在不同參數(shù)標準下的變化情況,便于對數(shù)據(jù)的綜合分析。
使用工具:Free Spire.Presentation for Java(免費版)
Jar文件獲取及導入:
方法1:通過官網(wǎng)下載jar文件包。下載后,解壓文件,并將lib文件夾下的Spire.Presentation.jar導入java程序。參考如下導入效果:
方法2:通過maven倉庫安裝導入??蓞⒖?a target="_blank" href="http://www.dbjr.com.cn/article/164716.htm">導入方法。
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(); //添加一個柱狀圖 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è)置系列標簽數(shù)據(jù)來源 chart.getSeries().setSeriesLabel(chart.getChartData().get("B1", "C1")); //設(shè)置分類標簽數(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ù)標簽值 chart.getSeries().get(1).setType(ChartType.LINE_MARKERS);//將系列2的圖表類型設(shè)置為折線圖 chart.getSeries().get(1).setUseSecondAxis(true);//將系列2繪制在次坐標軸 chart.getSecondaryValueAxis().getMajorGridTextLines().setFillType(FillFormatType.NONE);//不顯示次坐標軸的網(wǎng)格線 //設(shè)置系列重疊 chart.setOverLap(-30); //設(shè)置分類間距 chart.setGapDepth(200); //保存文檔 presentation.saveToFile("chart.pptx", FileFormat.PPTX_2013); presentation.dispose(); } }
圖表添加效果:
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
基于Java Socket實現(xiàn)一個簡易在線聊天功能(一)
這篇文章主要給大家介紹基于Java Socket實現(xiàn)一個簡易在線聊天功能(一),分為客戶端和服務(wù)端兩段代碼,非常具有參考價值,感興趣的朋友一起學習吧2016-05-05Springboot2.7+Minio8 實現(xiàn)大文件分片上傳
本文主要介紹了Springboot2.7+Minio8 實現(xiàn)大文件分片上傳,通過文件切片上傳,我們能夠提高文件上傳的速度,優(yōu)化用戶體驗,具有一定的參考價值,感興趣的可以了解一下2023-12-12Spring?BOOT?AOP基礎(chǔ)應(yīng)用教程
這篇文章主要介紹了Spring?BOOT?AOP的使用,文章從相關(guān)問題展開全文內(nèi)容詳情,具有一定的參考價值,需要的小伙伴可以參考一下2022-07-07Spring Security Remember me使用及原理詳解
這篇文章主要介紹了Spring Security Remember me使用及原理詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-09-09解決異常處理問題:getReader()?has?already?been?called?for?this
這篇文章主要介紹了解決異常處理:getReader()?has?already?been?called?for?this問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-01-01