# แผนภูมิเอกสาร PPT ผ่าน Java

> โค้ดตัวอย่าง Java เพื่อวาดและแปลงแผนภูมิหรือไดอะแกรมในไฟล์ PPT บน Java Runtime Environment สำหรับแอปพลิเคชัน JSP/JSF และแอปพลิเคชันเดสก์ท็อป

Source: https://products.aspose.com/slides/th/java/chart/ppt/
Updated: 2026-08-11



## วิธีสร้างแผนภูมิไฟล์ PPT โดยใช้ Java

 ในการสร้างแผนภูมิไฟล์ PPT เราจะใช้
 [Aspose.Slides สำหรับ Java](https://products.aspose.com/slides/th/java/)
 API ซึ่งเป็น API การสร้างแผนภูมิที่มีคุณลักษณะหลากหลาย มีประสิทธิภาพ และใช้งานง่ายสำหรับแพลตฟอร์ม Java คุณสามารถดาวน์โหลดเวอร์ชันล่าสุดได้โดยตรงจาก
 [Maven](https://repository.aspose.com/webapp/#/artifacts/browse/tree/General/repo/com/aspose/aspose-slides)
 และติดตั้งภายในโปรเจ็กต์ที่ใช้ Maven โดยเพิ่มการกำหนดค่าต่อไปนี้ใน pom.xml

### ที่เก็บ

```xml

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://releases.aspose.com/java/repo/</url>
</repository>

```

### การพึ่งพา

```xml

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-slides</artifactId>
    <version>version of aspose-slides API</version>
    <classifier>jdk17</classifier>
</dependency>
```

## ขั้นตอนในการสร้างแผนภูมิไฟล์ PPT ใน Java

การสร้างแผนภูมิเอกสารพื้นฐานด้วย API ของ [Aspose.Slides for Java](https://products.aspose.com/slides/th/java/) สามารถทำได้โดยใช้โค้ดเพียงไม่กี่บรรทัด

ยกตัวอย่างวัตถุคลาสการนำเสนอ

รับสไลด์แรก

เพิ่มแผนภูมิด้วยข้อมูลเริ่มต้น

ตั้งชื่อแผนภูมิ

ตั้งค่าชุดแรกเป็น Show Values

กำหนดดัชนีของแผ่นข้อมูลแผนภูมิ

รับแผ่นงานข้อมูลแผนภูมิ

ลบซีรี่ส์และหมวดหมู่ที่สร้างโดยค่าเริ่มต้น

เพิ่มซีรีส์และหมวดหมู่ใหม่

ใช้แผนภูมิชุดแรก

เติมข้อมูลชุดข้อมูล

ตั้งค่าสีเติมสำหรับซีรี่ส์

สร้างป้ายกำกับที่กำหนดเองสำหรับแต่ละหมวดหมู่สำหรับซีรีส์ใหม่

บันทึกการนำเสนอด้วยแผนภูมิ

## ความต้องการของระบบ

 Aspose.Slides สำหรับ Java รองรับบนแพลตฟอร์มหลักและระบบปฏิบัติการทั้งหมด โปรดตรวจสอบให้แน่ใจว่าคุณมีข้อกำหนดเบื้องต้นดังต่อไปนี้

- Microsoft Windows หรือ OS ที่เข้ากันได้กับ Java Runtime Environment สำหรับแอปพลิเคชัน JSP/JSF และแอปพลิเคชันเดสก์ท็อป
- รับเวอร์ชันล่าสุดของ Aspose.Slides สำหรับ Java โดยตรงจาก
 [Maven](https://repository.aspose.com/webapp/#/artifacts/browse/tree/General/repo/com/aspose/aspose-slides)

### สร้างแผนภูมิไฟล์ PPT - Java

```cs
//Instantiate Presentation class
Presentation pres = new Presentation();

//Access first slide
ISlide sld = pres.getSlides().get_Item(0);

// Add chart with default data
IChart chart = sld.getShapes().addChart(ChartType.ClusteredColumn, 0, 0, 500, 500);

//Setting chart Title
//chart.getChartTitle().TextFrameForOverriding.Text = "Title";
chart.getChartTitle().addTextFrameForOverriding("Title");
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True);
chart.getChartTitle().setHeight(20);
chart.hasTitle(true);

//Set first series to Show Values
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true);

//Setting the index of chart data sheet
int defaultWorksheetIndex = 0;

//Getting the chart data worksheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();

//Delete default generated series and categories
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
int s = chart.getChartData().getSeries().size();
s = chart.getChartData().getCategories().size();

//Adding new series
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.getType());
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.getType());

//Adding new categories
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1"));
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2"));
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3"));

//Take first chart series
IChartSeries series = chart.getChartData().getSeries().get_Item(0);

//Now populating series data

series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30));

//Setting fill color for series
series.getFormat().getFill().setFillType(FillType.Solid);
series.getFormat().getFill().getSolidFillColor().setColor(java.awt.Color.RED);

//Take second chart series
series = chart.getChartData().getSeries().get_Item(1);

//Now populating series data
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 2, 30));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 2, 10));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 2, 60));

//Setting fill color for series
series.getFormat().getFill().setFillType(FillType.Solid);
series.getFormat().getFill().getSolidFillColor().setColor(java.awt.Color.GREEN);

//create custom labels for each of categories for new series

//first label will be show Category name
IDataLabel lbl = series.getDataPoints().get_Item(0).getLabel();
lbl.getDataLabelFormat().setShowCategoryName(true);

lbl = series.getDataPoints().get_Item(1).getLabel();
lbl.getDataLabelFormat().setShowSeriesName(true);

//Show value for third label
lbl = series.getDataPoints().get_Item(2).getLabel();
lbl.getDataLabelFormat().setShowValue(true);
lbl.getDataLabelFormat().setShowSeriesName(true);
lbl.getDataLabelFormat().setSeparator("/");

//Save presentation with chart
pres.save("AsposeChart.ppt",SaveFormat.Ppt);

```

## เกี่ยวกับ Aspose.Slides สำหรับ Java API

 สร้างแผนภูมิเอกสาร PPT ทันทีโดยไปที่ .ของเรา
 [เว็บไซต์สาธิตสด](https://products.aspose.app/slides/chart)
 . การสาธิตสดมีประโยชน์ดังต่อไปนี้

A file with PPT extension represents PowerPoint file that consists of a collection of slides for displaying as SlideShow. It specifies the Binary File Format used by Microsoft PowerPoint 97-2003. A PPT file can contain several different types of information such as text, bulleted points, images, multimedia and other embedded OLE objects. Microsoft came up with newer file format for PowerPoint, known as PPTX, from 2007 onwards that is based on Office OpenXML and is different from this binary file format. Several other application programs such as OpenOffice Impress and Apple Keynote can also create PPT files.

## รูปแบบแผนภูมิอื่นๆ ที่รองรับ

- [PPTX](https://products.aspose.com/slides/th/java/chart/pptx/) — เปิดรูปแบบการนำเสนอ XML
