Crear gráficos PPT en Java

Use Aspose.Slides for Java para crear y dar formato a gráficos en archivos de presentación sin Microsoft PowerPoint.

Crear gráficos en archivos PPT con Java

Use Aspose.Slides for Java para crear y dar formato a gráficos en presentaciones PPT. La API ofrece objetos de gráfico como IChart, IChartDataWorkbook, IChartSeries e IDataLabel. Puede instalar el paquete aspose-slides en un proyecto basado en Maven agregando el repositorio y la dependencia siguientes.

Repositorio

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

Dependencia

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-slides</artifactId>
    <version>26.8</version>
    <classifier>jdk16</classifier>
</dependency>

Crear un gráfico en PPT – Java

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);
    IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 0, 0, 500, 500);

    chart.getChartTitle().addTextFrameForOverriding("Sales by quarter");
    chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True);
    chart.getChartTitle().setHeight(20);
    chart.setTitle(true);

    chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true);

    int defaultWorksheetIndex = 0;
    IChartDataWorkbook chartDataWorkbook = chart.getChartData().getChartDataWorkbook();

    chart.getChartData().getSeries().clear();
    chart.getChartData().getCategories().clear();

    chart.getChartData().getSeries().add(chartDataWorkbook.getCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.getType());
    chart.getChartData().getSeries().add(chartDataWorkbook.getCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.getType());

    chart.getChartData().getCategories().add(chartDataWorkbook.getCell(defaultWorksheetIndex, 1, 0, "Category 1"));
    chart.getChartData().getCategories().add(chartDataWorkbook.getCell(defaultWorksheetIndex, 2, 0, "Category 2"));
    chart.getChartData().getCategories().add(chartDataWorkbook.getCell(defaultWorksheetIndex, 3, 0, "Category 3"));

    IChartSeries firstSeries = chart.getChartData().getSeries().get_Item(0);
    firstSeries.getDataPoints().addDataPointForBarSeries(chartDataWorkbook.getCell(defaultWorksheetIndex, 1, 1, 20));
    firstSeries.getDataPoints().addDataPointForBarSeries(chartDataWorkbook.getCell(defaultWorksheetIndex, 2, 1, 50));
    firstSeries.getDataPoints().addDataPointForBarSeries(chartDataWorkbook.getCell(defaultWorksheetIndex, 3, 1, 30));
    firstSeries.getFormat().getFill().setFillType(FillType.Solid);
    firstSeries.getFormat().getFill().getSolidFillColor().setColor(java.awt.Color.RED);

    IChartSeries secondSeries = chart.getChartData().getSeries().get_Item(1);
    secondSeries.getDataPoints().addDataPointForBarSeries(chartDataWorkbook.getCell(defaultWorksheetIndex, 1, 2, 30));
    secondSeries.getDataPoints().addDataPointForBarSeries(chartDataWorkbook.getCell(defaultWorksheetIndex, 2, 2, 10));
    secondSeries.getDataPoints().addDataPointForBarSeries(chartDataWorkbook.getCell(defaultWorksheetIndex, 3, 2, 60));
    secondSeries.getFormat().getFill().setFillType(FillType.Solid);
    secondSeries.getFormat().getFill().getSolidFillColor().setColor(java.awt.Color.GREEN);

    IDataLabel firstDataLabel = secondSeries.getDataPoints().get_Item(0).getLabel();
    firstDataLabel.getDataLabelFormat().setShowCategoryName(true);

    IDataLabel secondDataLabel = secondSeries.getDataPoints().get_Item(1).getLabel();
    secondDataLabel.getDataLabelFormat().setShowSeriesName(true);

    IDataLabel thirdDataLabel = secondSeries.getDataPoints().get_Item(2).getLabel();
    thirdDataLabel.getDataLabelFormat().setShowValue(true);
    thirdDataLabel.getDataLabelFormat().setShowSeriesName(true);
    thirdDataLabel.getDataLabelFormat().setSeparator("/");

    presentation.save("chart-presentation.ppt", SaveFormat.Ppt);
} finally {
    presentation.dispose();
}

Cómo crear gráficos en archivos PPT en Java

Cree gráficos en archivos PPT con Aspose.Slides for Java.

  1. Cree un objeto Presentation.
  2. Obtenga la primera ISlide de la presentación.
  3. Agregue un objeto IChart con datos predeterminados.
  4. Establezca el título del gráfico y las opciones de las etiquetas de datos.
  5. Obtenga el objeto IChartDataWorkbook y borre las series y categorías predeterminadas.
  6. Agregue nuevas series y categorías.
  7. Rellene los datos de las series y establezca sus colores de relleno.
  8. Cree etiquetas de datos personalizadas para la serie del gráfico.
  9. Guarde la presentación con el gráfico.

Requisitos del sistema

Aspose.Slides for Java es compatible con las principales plataformas de escritorio y servidor. Asegúrese de que su proyecto cumpla estos requisitos previos.

  • Microsoft Windows, Linux, macOS u otro sistema operativo con un entorno de ejecución de Java compatible.
  • Obtenga la versión más reciente de Aspose.Slides for Java desde Maven .

Creado con Aspose.Slides

Crear gráficos PPT en línea

La aplicación gratuita Aspose.Slides Chart está creada con Aspose.Slides for Java, la misma API que el código anterior. Ábrala y descubra lo que la API puede hacer con sus propios archivos PPT.

  • Funciona en su navegador, sin instalar nada.
  • Vea cómo Aspose.Slides crea gráficos antes de escribir código.
  • Cree un gráfico a partir de datos de Excel o de una tabla.
  • Descárguelo como archivo PPT o como imagen.

Qué es PPT Formato de archivo

Un archivo PPT es un archivo de presentación de Microsoft PowerPoint 97-2003. Almacena diapositivas, texto, imágenes, multimedia, gráficos y objetos incrustados en el formato de archivo binario de PowerPoint usado antes del formato Open XML PPTX.

Leer más

Otros formatos compatibles para gráficos

Con Java, también puede crear gráficos en otros formatos.