# Gráfico de documentos PPTX a través de Java

> Código de muestra de Java para dibujar y convertir gráficos o diagramas en un archivo PPTX en Java Runtime Environment para aplicaciones JSP/JSF y aplicaciones de escritorio.

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



## Cómo crear gráficos de archivos PPTX usando Java

 Para crear gráficos de archivos PPTX, usaremos
 [Aspose.Slides para Java](https://products.aspose.com/slides/es/java/)
 API que es una API de gráficos rica en funciones, potente y fácil de usar para la plataforma Java. Puedes descargar su última versión directamente desde
 [Maven](https://repository.aspose.com/webapp/#/artifacts/browse/tree/General/repo/com/aspose/aspose-slides)
 e instálelo dentro de su proyecto basado en Maven agregando las siguientes configuraciones al pom.xml.

### Repositorio

```xml

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

```

### Dependencia

```xml

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

## Pasos para crear gráficos de archivos PPTX en Java

Se puede hacer un gráfico básico de documentos con [Aspose.Slides for Java](https://products.aspose.com/slides/es/java/) API con solo unas pocas líneas de código.

Instanciar objeto de clase de presentación.

Obtenga la primera diapositiva.

Agregar gráfico con datos predeterminados.

Establecer el título del gráfico.

Establezca la primera serie en Mostrar valores.

Establezca el índice de la hoja de datos del gráfico.

Obtenga la hoja de trabajo de datos del gráfico.

Eliminar series y categorías generadas por defecto.

Adición de nuevas series y categorías.

Tome la primera serie de cartas.

Rellenar datos de series.

Establecer color de relleno para la serie.

cree etiquetas personalizadas para cada una de las categorías para nuevas series.

Guardar presentación con gráfico.

## Requisitos del sistema

 Aspose.Slides para Java es compatible con todas las principales plataformas y sistemas operativos. Por favor, asegúrese de que tiene los siguientes requisitos previos.

- Microsoft Windows o un sistema operativo compatible con Java Runtime Environment para aplicaciones JSP/JSF y aplicaciones de escritorio.
- Obtenga la última versión de Aspose.Slides para Java directamente desde
 [Maven](https://repository.aspose.com/webapp/#/artifacts/browse/tree/General/repo/com/aspose/aspose-slides) .

### Crear gráfico de archivos PPTX - 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.pptx",SaveFormat.Pptx);

```

## Acerca de Aspose.Slides para la API de Java

 Genere gráficos de documentos PPTX ahora mismo visitando nuestro
 [Sitio web de demostraciones en vivo](https://products.aspose.app/slides/chart)
 . La demostración en vivo tiene los siguientes beneficios

Files with PPTX extension are presentation files created with popular Microsoft PowerPoint application. Unlike the previous version of presentation file format PPT which was binary, the PPTX format is based on the Microsoft PowerPoint open XML presentation file format. A presentation file is a collection of slides where each slide can comprise of text, images, formatting, animations, and other media. These slides are presented to audience in the form of slideshows with custom presentation settings.

## Otros formatos de gráficos admitidos

- [PPT](https://products.aspose.com/slides/es/java/chart/ppt/) — Microsoft PowerPoint 97-2003
