图表,是指将既得数据用图形的方式表示出来。在前文中我们介绍过如何使用Java程序来为Excel文档创建图表的方法。本文将通过使用Java程序来演示如何创建PowerPoint图表及为图表添加趋势线。趋势线的运用能够显示数据的变化趋势,同时能够帮助预测数据的未来值。
Jar文件获取及导入:
方法1:通过官网下载获取jar包。解压后将lib文件夹下的Spire.Presentation.jar文件导入Java程序。(如下图)
方法2:通过maven仓库安装导入。具体安装教程参见此网页。
【示例1】创建图表
import com.spire.presentation.*;
import com.spire.pdf.tables.table.*;
import com.spire.presentation.charts.*;
import com.spire.presentation.drawing.FillFormatType;
import java.awt.geom.Rectangle2D;
import java.lang.Object;
public class AddChart {
public static void main(String[] args) throws Exception {
//实例化一个Presentation对象
Presentation presentation = new Presentation();
//插入柱形图
Rectangle2D.Double rect = new Rectangle2D.Double(40, 100, 550, 320);
IChart chart = null;
chart = presentation.getSlides().get(0).getShapes().appendChart(ChartType.COLUMN_CLUSTERED, rect);
//添加表名
chart.getChartTitle().getTextProperties().setText(