Crear o Actualizar Gráficos en Presentaciones de PowerPoint

Resumen

Este artículo describe cómo crear Gráficos en Presentaciones de PowerPoint en Java. También puedes actualizar los gráficos. Cubre estos temas.

Gráfico: Normal

Gráfico: Disperso

Gráfico: Circular

Gráfico: Mapa de Árbol

Gráfico: Acciones

Gráfico: Caja y Bigote

Gráfico: Embudo

Gráfico: Estallido Solar

Gráfico: Histograma

Gráfico: Radar

Gráfico: Multiclase

Gráfico: Mapa

Acción: Actualizar Gráfico

Crear Gráfico

Los gráficos ayudan a las personas a visualizar rápidamente datos y obtener insights, que pueden no ser obvios a partir de una tabla o una hoja de cálculo.

¿Por Qué Crear Gráficos?

Al usar gráficos, puedes

  • agregar, condensar o resumir grandes cantidades de datos en una sola diapositiva de una presentación
  • exponer patrones y tendencias en los datos
  • deducir la dirección y el impulso de los datos a lo largo del tiempo o con respecto a una unidad de medida específica
  • identificar valores atípicos, aberraciones, desviaciones, errores, datos sin sentido, etc.
  • comunicar o presentar datos complejos

En PowerPoint, puedes crear gráficos a través de la función de insertar, que proporciona plantillas utilizadas para diseñar muchos tipos de gráficos. Usando Aspose.Slides, puedes crear gráficos regulares (basados en tipos de gráficos populares) y gráficos personalizados.

Creando Gráficos Normales

Pasos: Crear Gráfico

Pasos del Código:

  1. Crea una instancia de la clase Presentation.
  2. Obtén la referencia de una diapositiva a través de su índice.
  3. Agrega un gráfico con algunos datos y especifica tu tipo de gráfico preferido.
  4. Agrega un título para el gráfico.
  5. Accede a la hoja de datos del gráfico.
  6. Limpia todas las series y categorías predeterminadas.
  7. Agrega nuevas series y categorías.
  8. Agrega algunos nuevos datos del gráfico para las series del gráfico.
  9. Agrega un color de relleno para las series del gráfico.
  10. Agrega etiquetas para las series del gráfico.
  11. Escribe la presentación modificada como un archivo PPTX.

Este código PHP te muestra cómo crear un gráfico normal:

  # Instancia una clase de presentación que representa un archivo PPTX
  $pres = new Presentation();
  try {
    # Accede a la primera diapositiva
    $sld = $pres->getSlides()->get_Item(0);
    # Agrega un gráfico con sus datos predeterminados
    $chart = $sld->getShapes()->addChart(ChartType::ClusteredColumn, 0, 0, 500, 500);
    # Establece el título del gráfico
    $chart->getChartTitle()->addTextFrameForOverriding("Título de Ejemplo");
    $chart->getChartTitle()->getTextFrameForOverriding()->getTextFrameFormat()->setCenterText(NullableBool::True);
    $chart->getChartTitle()->setHeight(20);
    $chart->hasTitle();
    # Establece la primera serie para mostrar valores
    $chart->getChartData()->getSeries()->get_Item(0)->getLabels()->getDefaultDataLabelFormat()->setShowValue(true);
    # Establece el índice para la hoja de datos del gráfico
    $defaultWorksheetIndex = 0;
    # Obtiene la hoja de trabajo de datos del gráfico
    $fact = $chart->getChartData()->getChartDataWorkbook();
    # Elimina las series y categorías generadas por defecto
    $chart->getChartData()->getSeries()->clear();
    $chart->getChartData()->getCategories()->clear();
    $s = $chart->getChartData()->getSeries()->size();
    $s = $chart->getChartData()->getCategories()->size();
    # Agrega nuevas series
    $chart->getChartData()->getSeries()->add($fact->getCell($defaultWorksheetIndex, 0, 1, "Serie 1"), $chart->getType());
    $chart->getChartData()->getSeries()->add($fact->getCell($defaultWorksheetIndex, 0, 2, "Serie 2"), $chart->getType());
    # Agrega nuevas categorías
    $chart->getChartData()->getCategories()->add($fact->getCell($defaultWorksheetIndex, 1, 0, "Categoría 1"));
    $chart->getChartData()->getCategories()->add($fact->getCell($defaultWorksheetIndex, 2, 0, "Categoría 2"));
    $chart->getChartData()->getCategories()->add($fact->getCell($defaultWorksheetIndex, 3, 0, "Categoría 3"));
    # Toma la primera serie del gráfico
    $series = $chart->getChartData()->getSeries()->get_Item(0);
    # Ahora pobla los datos de la serie
    $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));
    # Establece el color de relleno para la serie
    $series->getFormat()->getFill()->setFillType(FillType::Solid);
    $series->getFormat()->getFill()->getSolidFillColor()->setColor(java("java.awt.Color")->RED);
    # Toma la segunda serie del gráfico
    $series = $chart->getChartData()->getSeries()->get_Item(1);
    # Pobla los datos de la serie
    $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));
    # Establece el color de relleno para la serie
    $series->getFormat()->getFill()->setFillType(FillType::Solid);
    $series->getFormat()->getFill()->getSolidFillColor()->setColor(java("java.awt.Color")->GREEN);
    # Crea etiquetas personalizadas para cada categoría para la nueva serie
    # Establece la primera etiqueta para mostrar el nombre de la Categoría
    $lbl = $series->getDataPoints()->get_Item(0)->getLabel();
    $lbl->getDataLabelFormat()->setShowCategoryName(true);
    $lbl = $series->getDataPoints()->get_Item(1)->getLabel();
    $lbl->getDataLabelFormat()->setShowSeriesName(true);
    # Muestra el valor para la tercera etiqueta
    $lbl = $series->getDataPoints()->get_Item(2)->getLabel();
    $lbl->getDataLabelFormat()->setShowValue(true);
    $lbl->getDataLabelFormat()->setShowSeriesName(true);
    $lbl->getDataLabelFormat()->setSeparator("/");
    # Guarda la presentación con el gráfico
    $pres->save("output.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Creando Gráficos Dispersos

Los gráficos dispersos (también conocidos como gráficas de dispersión o gráficos x-y) se utilizan a menudo para buscar patrones o demostrar correlaciones entre dos variables.

Es posible que desees usar un gráfico disperso cuando

  • tienes datos numéricos pareados
  • tienes 2 variables que se emparejan bien
  • deseas determinar si 2 variables están relacionadas
  • tienes una variable independiente que tiene múltiples valores para una variable dependiente

Pasos: Crear Gráfico Disperso | Pasos: Crear Gráfico Disperso de PowerPoint | Pasos: Crear Gráfico Disperso de Presentación de PowerPoint

  1. Por favor, sigue los pasos mencionados anteriormente en Creando Gráficos Normales
  2. Para el tercer paso, agrega un gráfico con algunos datos y especifica tu tipo de gráfico como uno de los siguientes
    1. ChartType::ScatterWithMarkers - Representa un Gráfico Disperso.
    2. ChartType::ScatterWithSmoothLinesAndMarkers - Representa un Gráfico Disperso conectado por curvas, con marcadores de datos.
    3. ChartType::ScatterWithSmoothLines - Representa un Gráfico Disperso conectado por curvas, sin marcadores de datos.
    4. ChartType::ScatterWithStraightLinesAndMarkers - Representa un Gráfico Disperso conectado por líneas, con marcadores de datos.
    5. ChartType::ScatterWithStraightLines - Representa un Gráfico Disperso conectado por líneas, sin marcadores de datos.

Este código PHP te muestra cómo crear gráficos dispersos con una serie diferente de marcadores:

  # Instancia una clase de presentación que representa un archivo PPTX
  $pres = new Presentation();
  try {
    # Accede a la primera diapositiva
    $slide = $pres->getSlides()->get_Item(0);
    # Crea el gráfico predeterminado
    $chart = $slide->getShapes()->addChart(ChartType::ScatterWithSmoothLines, 0, 0, 400, 400);
    # Obtiene el índice de la hoja de datos predeterminada del gráfico
    $defaultWorksheetIndex = 0;
    # Obtiene la hoja de trabajo de datos del gráfico
    $fact = $chart->getChartData()->getChartDataWorkbook();
    # Elimina la serie de demostración
    $chart->getChartData()->getSeries()->clear();
    # Agrega nuevas series
    $chart->getChartData()->getSeries()->add($fact->getCell($defaultWorksheetIndex, 1, 1, "Serie 1"), $chart->getType());
    $chart->getChartData()->getSeries()->add($fact->getCell($defaultWorksheetIndex, 1, 3, "Serie 2"), $chart->getType());
    # Toma la primera serie del gráfico
    $series = $chart->getChartData()->getSeries()->get_Item(0);
    # Agrega un nuevo punto (1:3) a la serie
    $series->getDataPoints()->addDataPointForScatterSeries($fact->getCell($defaultWorksheetIndex, 2, 1, 1), $fact->getCell($defaultWorksheetIndex, 2, 2, 3));
    # Agrega un nuevo punto (2:10)
    $series->getDataPoints()->addDataPointForScatterSeries($fact->getCell($defaultWorksheetIndex, 3, 1, 2), $fact->getCell($defaultWorksheetIndex, 3, 2, 10));
    # Cambia el tipo de serie
    $series->setType(ChartType::ScatterWithStraightLinesAndMarkers);
    # Cambia el marcador de la serie del gráfico
    $series->getMarker()->setSize(10);
    $series->getMarker()->setSymbol(MarkerStyleType::Star);
    # Toma la segunda serie del gráfico
    $series = $chart->getChartData()->getSeries()->get_Item(1);
    # Agrega un nuevo punto (5:2) allí
    $series->getDataPoints()->addDataPointForScatterSeries($fact->getCell($defaultWorksheetIndex, 2, 3, 5), $fact->getCell($defaultWorksheetIndex, 2, 4, 2));
    # Agrega un nuevo punto (3:1)
    $series->getDataPoints()->addDataPointForScatterSeries($fact->getCell($defaultWorksheetIndex, 3, 3, 3), $fact->getCell($defaultWorksheetIndex, 3, 4, 1));
    # Agrega un nuevo punto (2:2)
    $series->getDataPoints()->addDataPointForScatterSeries($fact->getCell($defaultWorksheetIndex, 4, 3, 2), $fact->getCell($defaultWorksheetIndex, 4, 4, 2));
    # Agrega un nuevo punto (5:1)
    $series->getDataPoints()->addDataPointForScatterSeries($fact->getCell($defaultWorksheetIndex, 5, 3, 5), $fact->getCell($defaultWorksheetIndex, 5, 4, 1));
    # Cambia el marcador de la serie del gráfico
    $series->getMarker()->setSize(10);
    $series->getMarker()->setSymbol(MarkerStyleType::Circle);
    $pres->save("AsposeChart_out.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Creando Gráficos Circulares

Los gráficos circulares son los más apropiados para mostrar la relación parte-todo en los datos, especialmente cuando los datos contienen etiquetas categóricas con valores numéricos. Sin embargo, si tus datos contienen muchas partes o etiquetas, es posible que desees considerar usar un gráfico de barras en su lugar.

Pasos: Crear Gráfico Circular | Pasos: Crear Gráfico Circular de PowerPoint | Pasos: Crear Gráfico Circular de Presentación de PowerPoint

  1. Crea una instancia de la clase Presentation.
  2. Obtén la referencia de una diapositiva por su índice.
  3. Agrega un gráfico con datos predeterminados junto con el tipo deseado (en este caso, ChartType.Pie).
  4. Accede a los datos del gráfico IChartDataWorkbook.
  5. Limpia las series y categorías predeterminadas.
  6. Agrega nuevas series y categorías.
  7. Agrega nuevos datos del gráfico para las series del gráfico.
  8. Agrega nuevos puntos para los gráficos y agrega colores personalizados para los sectores del gráfico circular.
  9. Establece etiquetas para las series.
  10. Establece líneas de líder para las etiquetas de las series.
  11. Establece el ángulo de rotación para los sectores del gráfico circular.
  12. Escribe la presentación modificada en un archivo PPTX.

Este código PHP te muestra cómo crear un gráfico circular:

  # Instancia una clase de presentación que representa un archivo PPTX
  $pres = new Presentation();
  try {
    # Accede a la primera diapositiva
    $slides = $pres->getSlides()->get_Item(0);
    # Agrega un gráfico con datos predeterminados
    $chart = $slides->getShapes()->addChart(ChartType::Pie, 100, 100, 400, 400);
    # Establece el título del gráfico
    $chart->getChartTitle()->addTextFrameForOverriding("Título de Ejemplo");
    $chart->getChartTitle()->getTextFrameForOverriding()->getTextFrameFormat()->setCenterText(NullableBool::True);
    $chart->getChartTitle()->setHeight(20);
    $chart->setTitle(true);
    # Establece la primera serie para mostrar valores
    $chart->getChartData()->getSeries()->get_Item(0)->getLabels()->getDefaultDataLabelFormat()->setShowValue(true);
    # Establece el índice para la hoja de datos del gráfico
    $defaultWorksheetIndex = 0;
    # Obtiene la hoja de trabajo de datos del gráfico
    $fact = $chart->getChartData()->getChartDataWorkbook();
    # Elimina las series y categorías generadas por defecto
    $chart->getChartData()->getSeries()->clear();
    $chart->getChartData()->getCategories()->clear();
    # Agrega nuevas categorías
    $chart->getChartData()->getCategories()->add($fact->getCell(0, 1, 0, "Primer Trimestre"));
    $chart->getChartData()->getCategories()->add($fact->getCell(0, 2, 0, "Segundo Trimestre"));
    $chart->getChartData()->getCategories()->add($fact->getCell(0, 3, 0, "Tercer Trimestre"));
    # Agrega nuevas series
    $series = $chart->getChartData()->getSeries()->add($fact->getCell(0, 0, 1, "Serie 1"), $chart->getType());
    # Pobla los datos de la serie
    $series->getDataPoints()->addDataPointForPieSeries($fact->getCell($defaultWorksheetIndex, 1, 1, 20));
    $series->getDataPoints()->addDataPointForPieSeries($fact->getCell($defaultWorksheetIndex, 2, 1, 50));
    $series->getDataPoints()->addDataPointForPieSeries($fact->getCell($defaultWorksheetIndex, 3, 1, 30));
    # No funciona en la nueva versión
    # Agregar nuevos puntos y establecer el color de los sectores
    # series.IsColorVaried = true;
    $chart->getChartData()->getSeriesGroups()->get_Item(0)->setColorVaried(true);
    $point = $series->getDataPoints()->get_Item(0);
    $point->getFormat()->getFill()->setFillType(FillType::Solid);
    $point->getFormat()->getFill()->getSolidFillColor()->setColor(java("java.awt.Color")->CYAN);
    # Establece el borde del sector
    $point->getFormat()->getLine()->getFillFormat()->setFillType(FillType::Solid);
    $point->getFormat()->getLine()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->GRAY);
    $point->getFormat()->getLine()->setWidth(3.0);
    $point->getFormat()->getLine()->setStyle(LineStyle->ThinThick);
    $point->getFormat()->getLine()->setDashStyle(LineDashStyle->DashDot);
    $point1 = $series->getDataPoints()->get_Item(1);
    $point1->getFormat()->getFill()->setFillType(FillType::Solid);
    $point1->getFormat()->getFill()->getSolidFillColor()->setColor(java("java.awt.Color")->ORANGE);
    # Establece el borde del sector
    $point1->getFormat()->getLine()->getFillFormat()->setFillType(FillType::Solid);
    $point1->getFormat()->getLine()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->BLUE);
    $point1->getFormat()->getLine()->setWidth(3.0);
    $point1->getFormat()->getLine()->setStyle(LineStyle->Single);
    $point1->getFormat()->getLine()->setDashStyle(LineDashStyle->LargeDashDot);
    $point2 = $series->getDataPoints()->get_Item(2);
    $point2->getFormat()->getFill()->setFillType(FillType::Solid);
    $point2->getFormat()->getFill()->getSolidFillColor()->setColor(java("java.awt.Color")->YELLOW);
    # Establece el borde del sector
    $point2->getFormat()->getLine()->getFillFormat()->setFillType(FillType::Solid);
    $point2->getFormat()->getLine()->getFillFormat()->getSolidFillColor()->setColor(java("java.awt.Color")->RED);
    $point2->getFormat()->getLine()->setWidth(2.0);
    $point2->getFormat()->getLine()->setStyle(LineStyle->ThinThin);
    $point2->getFormat()->getLine()->setDashStyle(LineDashStyle->LargeDashDotDot);
    # Crea etiquetas personalizadas para cada categoría para la nueva serie
    $lbl1 = $series->getDataPoints()->get_Item(0)->getLabel();
    # lbl.ShowCategoryName = true;
    $lbl1->getDataLabelFormat()->setShowValue(true);
    $lbl2 = $series->getDataPoints()->get_Item(1)->getLabel();
    $lbl2->getDataLabelFormat()->setShowValue(true);
    $lbl2->getDataLabelFormat()->setShowLegendKey(true);
    $lbl2->getDataLabelFormat()->setShowPercentage(true);
    $lbl3 = $series->getDataPoints()->get_Item(2)->getLabel();
    $lbl3->getDataLabelFormat()->setShowSeriesName(true);
    $lbl3->getDataLabelFormat()->setShowPercentage(true);
    # Muestra líneas de líder para el gráfico
    $series->getLabels()->getDefaultDataLabelFormat()->setShowLeaderLines(true);
    # Establece el Ángulo de Rotación para los Sectores del Gráfico Circular
    $chart->getChartData()->getSeriesGroups()->get_Item(0)->setFirstSliceAngle(180);
    # Guarda la presentación con un gráfico
    $pres->save("PieChart_out.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Creando Gráficos de Líneas

Los gráficos de líneas (también conocidos como gráficos de línea) son los más apropiados en situaciones donde deseas demostrar cambios en el valor a lo largo del tiempo. Usando un gráfico de línea, puedes comparar muchos datos a la vez, rastrear cambios y tendencias a lo largo del tiempo, resaltar anomalías en las series de datos, etc.

  1. Crea una instancia de la clase Presentation.
  2. Obtén la referencia de una diapositiva a través de su índice.
  3. Agrega un gráfico con datos predeterminados junto con el tipo deseado (en este caso, ChartType::Line).
  4. Accede a los datos del gráfico IChartDataWorkbook.
  5. Limpia las series y categorías predeterminadas.
  6. Agrega nuevas series y categorías.
  7. Agrega nuevos datos del gráfico para las series del gráfico.
  8. Escribe la presentación modificada en un archivo PPTX.

Este código PHP te muestra cómo crear un gráfico de líneas:

  $pres = new Presentation();
  try {
    $lineChart = $pres->getSlides()->get_Item(0)->getShapes()->addChart(ChartType::Line, 10, 50, 600, 350);
    $pres->save("lineChart.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Por defecto, los puntos en un gráfico de líneas se unen por líneas continuas rectas. Si deseas que los puntos se unan por guiones en su lugar, puedes especificar tu tipo de guion preferido de esta manera:

  $lineChart = $pres->getSlides()->get_Item(0)->getShapes()->addChart(ChartType::Line, 10, 50, 600, 350);
  foreach($lineChart->getChartData()->getSeries() as $series) {
    $series->getFormat()->getLine()->setDashStyle(LineDashStyle->Dash);
  }

Creando Gráficos de Mapa de Árbol

Los gráficos de mapa de árbol son los más apropiados para datos de ventas cuando deseas mostrar el tamaño relativo de las categorías de datos y (al mismo tiempo) llamar rápidamente la atención sobre los elementos que son grandes contribuyentes a cada categoría.

Pasos: Crear Gráfico de Mapa de Árbol | Pasos: Crear Gráfico de Mapa de Árbol de PowerPoint | Pasos: Crear Gráfico de Mapa de Árbol de Presentación de PowerPoint

  1. Crea una instancia de la Presentation clase.
  2. Obtén la referencia de una diapositiva a través de su índice.
  3. Agrega un gráfico con datos predeterminados junto con el tipo deseado (en este caso, ChartType.TreeMap).
  4. Accede a los datos del gráfico IChartDataWorkbook.
  5. Limpia las series y categorías predeterminadas.
  6. Agrega nuevas series y categorías.
  7. Agrega nuevos datos del gráfico para las series del gráfico.
  8. Escribe la presentación modificada en un archivo PPTX.

Este código PHP te muestra cómo crear un gráfico de mapa de árbol:

  $pres = new Presentation();
  try {
    $chart = $pres->getSlides()->get_Item(0)->getShapes()->addChart(ChartType::Treemap, 50, 50, 500, 400);
    $chart->getChartData()->getCategories()->clear();
    $chart->getChartData()->getSeries()->clear();
    $wb = $chart->getChartData()->getChartDataWorkbook();
    $wb->clear(0);
    # rama 1
    $leaf = $chart->getChartData()->getCategories()->add($wb->getCell(0, "C1", "Hoja1"));
    $leaf->getGroupingLevels()->setGroupingItem(1, "Tallo1");
    $leaf->getGroupingLevels()->setGroupingItem(2, "Rama1");
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "C2", "Hoja2"));
    $leaf = $chart->getChartData()->getCategories()->add($wb->getCell(0, "C3", "Hoja3"));
    $leaf->getGroupingLevels()->setGroupingItem(1, "Tallo2");
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "C4", "Hoja4"));
    # rama 2
    $leaf = $chart->getChartData()->getCategories()->add($wb->getCell(0, "C5", "Hoja5"));
    $leaf->getGroupingLevels()->setGroupingItem(1, "Tallo3");
    $leaf->getGroupingLevels()->setGroupingItem(2, "Rama2");
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "C6", "Hoja6"));
    $leaf = $chart->getChartData()->getCategories()->add($wb->getCell(0, "C7", "Hoja7"));
    $leaf->getGroupingLevels()->setGroupingItem(1, "Tallo4");
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "C8", "Hoja8"));
    $series = $chart->getChartData()->getSeries()->add(ChartType::Treemap);
    $series->getLabels()->getDefaultDataLabelFormat()->setShowCategoryName(true);
    $series->getDataPoints()->addDataPointForTreemapSeries($wb->getCell(0, "D1", 4));
    $series->getDataPoints()->addDataPointForTreemapSeries($wb->getCell(0, "D2", 5));
    $series->getDataPoints()->addDataPointForTreemapSeries($wb->getCell(0, "D3", 3));
    $series->getDataPoints()->addDataPointForTreemapSeries($wb->getCell(0, "D4", 6));
    $series->getDataPoints()->addDataPointForTreemapSeries($wb->getCell(0, "D5", 9));
    $series->getDataPoints()->addDataPointForTreemapSeries($wb->getCell(0, "D6", 9));
    $series->getDataPoints()->addDataPointForTreemapSeries($wb->getCell(0, "D7", 4));
    $series->getDataPoints()->addDataPointForTreemapSeries($wb->getCell(0, "D8", 3));
    $series->setParentLabelLayout(ParentLabelLayoutType::Overlapping);
    $pres->save("Treemap.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Creando Gráficos de Acciones

Pasos: Crear Gráfico de Acciones | Pasos: Crear Gráfico de Acciones de PowerPoint | Pasos: Crear Gráfico de Acciones de Presentación de PowerPoint

  1. Crea una instancia de la Presentation clase.
  2. Obtén la referencia de una diapositiva por su índice.
  3. Agrega un gráfico con datos predeterminados junto con el tipo deseado (ChartType.OpenHighLowClose).
  4. Accede a los datos del gráfico IChartDataWorkbook.
  5. Limpia las series y categorías predeterminadas.
  6. Agrega nuevas series y categorías.
  7. Agrega nuevos datos del gráfico para las series del gráfico.
  8. Especifica el formato de líneas de HiLow.
  9. Escribe la presentación modificada en un archivo PPTX.

Código PHP de muestra utilizado para crear un gráfico de acciones:

  $pres = new Presentation();
  try {
    $chart = $pres->getSlides()->get_Item(0)->getShapes()->addChart(ChartType::OpenHighLowClose, 50, 50, 600, 400, false);
    $chart->getChartData()->getSeries()->clear();
    $chart->getChartData()->getCategories()->clear();
    $wb = $chart->getChartData()->getChartDataWorkbook();
    $chart->getChartData()->getCategories()->add($wb->getCell(0, 1, 0, "A"));
    $chart->getChartData()->getCategories()->add($wb->getCell(0, 2, 0, "B"));
    $chart->getChartData()->getCategories()->add($wb->getCell(0, 3, 0, "C"));
    $chart->getChartData()->getSeries()->add($wb->getCell(0, 0, 1, "Apertura"), $chart->getType());
    $chart->getChartData()->getSeries()->add($wb->getCell(0, 0, 2, "Máximo"), $chart->getType());
    $chart->getChartData()->getSeries()->add($wb->getCell(0, 0, 3, "Mínimo"), $chart->getType());
    $chart->getChartData()->getSeries()->add($wb->getCell(0, 0, 4, "Cierre"), $chart->getType());
    $series = $chart->getChartData()->getSeries()->get_Item(0);
    $series->getDataPoints()->addDataPointForStockSeries($wb->getCell(0, 1, 1, 72));
    $series->getDataPoints()->addDataPointForStockSeries($wb->getCell(0, 2, 1, 25));
    $series->getDataPoints()->addDataPointForStockSeries($wb->getCell(0, 3, 1, 38));
    $series = $chart->getChartData()->getSeries()->get_Item(1);
    $series->getDataPoints()->addDataPointForStockSeries($wb->getCell(0, 1, 2, 172));
    $series->getDataPoints()->addDataPointForStockSeries($wb->getCell(0, 2, 2, 57));
    $series->getDataPoints()->addDataPointForStockSeries($wb->getCell(0, 3, 2, 57));
    $series = $chart->getChartData()->getSeries()->get_Item(2);
    $series->getDataPoints()->addDataPointForStockSeries($wb->getCell(0, 1, 3, 12));
    $series->getDataPoints()->addDataPointForStockSeries($wb->getCell(0, 2, 3, 12));
    $series->getDataPoints()->addDataPointForStockSeries($wb->getCell(0, 3, 3, 13));
    $series = $chart->getChartData()->getSeries()->get_Item(3);
    $series->getDataPoints()->addDataPointForStockSeries($wb->getCell(0, 1, 4, 25));
    $series->getDataPoints()->addDataPointForStockSeries($wb->getCell(0, 2, 4, 38));
    $series->getDataPoints()->addDataPointForStockSeries($wb->getCell(0, 3, 4, 50));
    $chart->getChartData()->getSeriesGroups()->get_Item(0)->getUpDownBars()->setUpDownBars(true);
    $chart->getChartData()->getSeriesGroups()->get_Item(0)->getHiLowLinesFormat()->getLine()->getFillFormat()->setFillType(FillType::Solid);
    foreach($chart->getChartData()->getSeries() as $ser) {
      $ser->getFormat()->getLine()->getFillFormat()->setFillType(FillType::NoFill);
    }
    $pres->save("output.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Creando Gráficos de Caja y Bigote

Pasos: Crear Gráfico de Caja y Bigote | Pasos: Crear Gráfico de Caja y Bigote de PowerPoint | Pasos: Crear Gráfico de Caja y Bigote de Presentación de PowerPoint

  1. Crea una instancia de la Presentation clase.
  2. Obtén la referencia de una diapositiva a través de su índice.
  3. Agrega un gráfico con datos predeterminados junto con el tipo deseado (ChartType.BoxAndWhisker).
  4. Accede a los datos del gráfico IChartDataWorkbook.
  5. Limpia las series y categorías predeterminadas.
  6. Agrega nuevas series y categorías.
  7. Agrega nuevos datos del gráfico para las series del gráfico.
  8. Escribe la presentación modificada en un archivo PPTX.

Este código PHP te muestra cómo crear un gráfico de caja y bigote:

  $pres = new Presentation();
  try {
    $chart = $pres->getSlides()->get_Item(0)->getShapes()->addChart(ChartType::BoxAndWhisker, 50, 50, 500, 400);
    $chart->getChartData()->getCategories()->clear();
    $chart->getChartData()->getSeries()->clear();
    $wb = $chart->getChartData()->getChartDataWorkbook();
    $wb->clear(0);
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "A1", "Categoría 1"));
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "A2", "Categoría 2"));
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "A3", "Categoría 3"));
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "A4", "Categoría 4"));
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "A5", "Categoría 5"));
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "A6", "Categoría 6"));
    $series = $chart->getChartData()->getSeries()->add(ChartType::BoxAndWhisker);
    $series->setQuartileMethod(QuartileMethodType::Exclusive);
    $series->setShowMeanLine(true);
    $series->setShowMeanMarkers(true);
    $series->setShowInnerPoints(true);
    $series->setShowOutlierPoints(true);
    $series->getDataPoints()->addDataPointForBoxAndWhiskerSeries($wb->getCell(0, "B1", 15));
    $series->getDataPoints()->addDataPointForBoxAndWhiskerSeries($wb->getCell(0, "B2", 41));
    $series->getDataPoints()->addDataPointForBoxAndWhiskerSeries($wb->getCell(0, "B3", 16));
    $series->getDataPoints()->addDataPointForBoxAndWhiskerSeries($wb->getCell(0, "B4", 10));
    $series->getDataPoints()->addDataPointForBoxAndWhiskerSeries($wb->getCell(0, "B5", 23));
    $series->getDataPoints()->addDataPointForBoxAndWhiskerSeries($wb->getCell(0, "B6", 16));
    $pres->save("BoxAndWhisker.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Creando Gráficos de Embudo

Pasos: Crear Gráfico de Embudo | Pasos: Crear Gráfico de Embudo de PowerPoint | Pasos: Crear Gráfico de Embudo de Presentación de PowerPoint

  1. Crea una instancia de la Presentation clase.
  2. Obtén la referencia de una diapositiva a través de su índice.
  3. Agrega un gráfico con datos predeterminados junto con el tipo deseado (ChartType.Funnel).
  4. Escribe la presentación modificada en un archivo PPTX.

El código PHP te muestra cómo crear un gráfico de embudo:

  $pres = new Presentation();
  try {
    $chart = $pres->getSlides()->get_Item(0)->getShapes()->addChart(ChartType::Funnel, 50, 50, 500, 400);
    $chart->getChartData()->getCategories()->clear();
    $chart->getChartData()->getSeries()->clear();
    $wb = $chart->getChartData()->getChartDataWorkbook();
    $wb->clear(0);
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "A1", "Categoría 1"));
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "A2", "Categoría 2"));
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "A3", "Categoría 3"));
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "A4", "Categoría 4"));
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "A5", "Categoría 5"));
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "A6", "Categoría 6"));
    $series = $chart->getChartData()->getSeries()->add(ChartType::Funnel);
    $series->getDataPoints()->addDataPointForFunnelSeries($wb->getCell(0, "B1", 50));
    $series->getDataPoints()->addDataPointForFunnelSeries($wb->getCell(0, "B2", 100));
    $series->getDataPoints()->addDataPointForFunnelSeries($wb->getCell(0, "B3", 200));
    $series->getDataPoints()->addDataPointForFunnelSeries($wb->getCell(0, "B4", 300));
    $series->getDataPoints()->addDataPointForFunnelSeries($wb->getCell(0, "B5", 400));
    $series->getDataPoints()->addDataPointForFunnelSeries($wb->getCell(0, "B6", 500));
    $pres->save("Funnel.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Creando Gráficos de Estallido Solar

Pasos: Crear Gráfico de Estallido Solar | Pasos: Crear Gráfico de Estallido Solar de PowerPoint | Pasos: Crear Gráfico de Estallido Solar de Presentación de PowerPoint

  1. Crea una instancia de la Presentation clase.
  2. Obtén la referencia de una diapositiva a través de su índice.
  3. Agrega un gráfico con datos predeterminados junto con el tipo deseado (en este caso,ChartType.sunburst).
  4. Escribe la presentación modificada en un archivo PPTX.

Este código PHP te muestra cómo crear un gráfico de estallido solar:

  $pres = new Presentation();
  try {
    $chart = $pres->getSlides()->get_Item(0)->getShapes()->addChart(ChartType::Sunburst, 50, 50, 500, 400);
    $chart->getChartData()->getCategories()->clear();
    $chart->getChartData()->getSeries()->clear();
    $wb = $chart->getChartData()->getChartDataWorkbook();
    $wb->clear(0);
    # rama 1
    $leaf = $chart->getChartData()->getCategories()->add($wb->getCell(0, "C1", "Hoja1"));
    $leaf->getGroupingLevels()->setGroupingItem(1, "Tallo1");
    $leaf->getGroupingLevels()->setGroupingItem(2, "Rama1");
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "C2", "Hoja2"));
    $leaf = $chart->getChartData()->getCategories()->add($wb->getCell(0, "C3", "Hoja3"));
    $leaf->getGroupingLevels()->setGroupingItem(1, "Tallo2");
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "C4", "Hoja4"));
    # rama 2
    $leaf = $chart->getChartData()->getCategories()->add($wb->getCell(0, "C5", "Hoja5"));
    $leaf->getGroupingLevels()->setGroupingItem(1, "Tallo3");
    $leaf->getGroupingLevels()->setGroupingItem(2, "Rama2");
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "C6", "Hoja6"));
    $leaf = $chart->getChartData()->getCategories()->add($wb->getCell(0, "C7", "Hoja7"));
    $leaf->getGroupingLevels()->setGroupingItem(1, "Tallo4");
    $chart->getChartData()->getCategories()->add($wb->getCell(0, "C8", "Hoja8"));
    $series = $chart->getChartData()->getSeries()->add(ChartType::Sunburst);
    $series->getLabels()->getDefaultDataLabelFormat()->setShowCategoryName(true);
    $series->getDataPoints()->addDataPointForSunburstSeries($wb->getCell(0, "D1", 4));
    $series->getDataPoints()->addDataPointForSunburstSeries($wb->getCell(0, "D2", 5));
    $series->getDataPoints()->addDataPointForSunburstSeries($wb->getCell(0, "D3", 3));
    $series->getDataPoints()->addDataPointForSunburstSeries($wb->getCell(0, "D4", 6));
    $series->getDataPoints()->addDataPointForSunburstSeries($wb->getCell(0, "D5", 9));
    $series->getDataPoints()->addDataPointForSunburstSeries($wb->getCell(0, "D6", 9));
    $series->getDataPoints()->addDataPointForSunburstSeries($wb->getCell(0, "D7", 4));
    $series->getDataPoints()->addDataPointForSunburstSeries($wb->getCell(0, "D8", 3));
    $pres->save("Sunburst.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Creando Gráficos de Histograma

Pasos: Crear Gráfico de Histograma | Pasos: Crear Gráfico de Histograma de PowerPoint | Pasos: Crear Gráfico de Histograma de Presentación de PowerPoint

  1. Crea una instancia de la Presentation clase.
  2. Obtén la referencia de una diapositiva a través de su índice.
  3. Agrega un gráfico con datos predeterminados junto con el tipo deseado (ChartType.Histogram).
  4. Accede a los datos del gráfico IChartDataWorkbook.
  5. Limpia las series y categorías predeterminadas.
  6. Agrega nuevas series y categorías.
  7. Escribe la presentación modificada en un archivo PPTX.

Este código PHP te muestra cómo crear un gráfico de histograma:

  $pres = new Presentation();
  try {
    $chart = $pres->getSlides()->get_Item(0)->getShapes()->addChart(ChartType::Histogram, 50, 50, 500, 400);
    $chart->getChartData()->getCategories()->clear();
    $chart->getChartData()->getSeries()->clear();
    $wb = $chart->getChartData()->getChartDataWorkbook();
    $wb->clear(0);
    $series = $chart->getChartData()->getSeries()->add(ChartType::Histogram);
    $series->getDataPoints()->addDataPointForHistogramSeries($wb->getCell(0, "A1", 15));
    $series->getDataPoints()->addDataPointForHistogramSeries($wb->getCell(0, "A2", -41));
    $series->getDataPoints()->addDataPointForHistogramSeries($wb->getCell(0, "A3", 16));
    $series->getDataPoints()->addDataPointForHistogramSeries($wb->getCell(0, "A4", 10));
    $series->getDataPoints()->addDataPointForHistogramSeries($wb->getCell(0, "A5", -23));
    $series->getDataPoints()->addDataPointForHistogramSeries($wb->getCell(0, "A6", 16));
    $chart->getAxes()->getHorizontalAxis()->setAggregationType(AxisAggregationType::Automatic);

Creando Gráficos de Radar

Pasos: Crear Gráfico de Radar | Pasos: Crear Gráfico de Radar de PowerPoint | Pasos: Crear Gráfico de Radar de Presentación de PowerPoint

  1. Crea una instancia de la Presentation clase.
  2. Obtén la referencia de una diapositiva a través de su índice.
  3. Agrega un gráfico con algunos datos y especifica tu tipo de gráfico preferido (ChartType::Radar en este caso).
  4. Escribe la presentación modificada en un archivo PPTX.

Este código PHP te muestra cómo crear un gráfico de radar:

  $pres = new Presentation();
  try {
    $pres->getSlides()->get_Item(0)->getShapes()->addChart(ChartType::Radar, 20, 20, 400, 300);
    $pres->save("Radar-chart.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Creando Gráficos Multiclase

Pasos: Crear Gráfico Multiclase | Pasos: Crear Gráfico Multiclase de PowerPoint | Pasos: Crear Gráfico Multiclase de Presentación de PowerPoint

  1. Crea una instancia de la Presentation clase.
  2. Obtén la referencia de una diapositiva a través de su índice.
  3. Agrega un gráfico con datos predeterminados junto con el tipo deseado (ChartType.ClusteredColumn).
  4. Accede a los datos del gráfico IChartDataWorkbook.
  5. Limpia las series y categorías predeterminadas.
  6. Agrega nuevas series y categorías.
  7. Agrega nuevos datos del gráfico para las series del gráfico.
  8. Escribe la presentación modificada en un archivo PPTX.

Este código PHP te muestra cómo crear un gráfico multiclase:

  $pres = new Presentation();
  try {
    $ch = $pres->getSlides()->get_Item(0)->getShapes()->addChart(ChartType::ClusteredColumn, 100, 100, 600, 450);
    $ch->getChartData()->getSeries()->clear();
    $ch->getChartData()->getCategories()->clear();
    $fact = $ch->getChartData()->getChartDataWorkbook();
    $fact->clear(0);
    $defaultWorksheetIndex = 0;
    $category = $ch->getChartData()->getCategories()->add($fact->getCell(0, "c2", "A"));
    $category->getGroupingLevels()->setGroupingItem(1, "Grupo1");
    $category = $ch->getChartData()->getCategories()->add($fact->getCell(0, "c3", "B"));
    $category = $ch->getChartData()->getCategories()->add($fact->getCell(0, "c4", "C"));
    $category->getGroupingLevels()->setGroupingItem(1, "Grupo2");
    $category = $ch->getChartData()->getCategories()->add($fact->getCell(0, "c5", "D"));
    $category = $ch->getChartData()->getCategories()->add($fact->getCell(0, "c6", "E"));
    $category->getGroupingLevels()->setGroupingItem(1, "Grupo3");
    $category = $ch->getChartData()->getCategories()->add($fact->getCell(0, "c7", "F"));
    $category = $ch->getChartData()->getCategories()->add($fact->getCell(0, "c8", "G"));
    $category->getGroupingLevels()->setGroupingItem(1, "Grupo4");
    $category = $ch->getChartData()->getCategories()->add($fact->getCell(0, "c9", "H"));
    # Agregando Series
    $series = $ch->getChartData()->getSeries()->add($fact->getCell(0, "D1", "Serie 1"), ChartType::ClusteredColumn);
    $series->getDataPoints()->addDataPointForBarSeries($fact->getCell($defaultWorksheetIndex, "D2", 10));
    $series->getDataPoints()->addDataPointForBarSeries($fact->getCell($defaultWorksheetIndex, "D3", 20));
    $series->getDataPoints()->addDataPointForBarSeries($fact->getCell($defaultWorksheetIndex, "D4", 30));
    $series->getDataPoints()->addDataPointForBarSeries($fact->getCell($defaultWorksheetIndex, "D5", 40));
    $series->getDataPoints()->addDataPointForBarSeries($fact->getCell($defaultWorksheetIndex, "D6", 50));
    $series->getDataPoints()->addDataPointForBarSeries($fact->getCell($defaultWorksheetIndex, "D7", 60));
    $series->getDataPoints()->addDataPointForBarSeries($fact->getCell($defaultWorksheetIndex, "D8", 70));
    $series->getDataPoints()->addDataPointForBarSeries($fact->getCell($defaultWorksheetIndex, "D9", 80));
    # Guarda la presentación con el gráfico
    $pres->save("AsposeChart_out.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Creando Gráficos de Mapa

Un gráfico de mapa es una visualización de un área que contiene datos. Los gráficos de mapa son los más adecuados para comparar datos o valores a través de regiones geográficas.

Pasos: Crear Gráfico de Mapa | Pasos: Crear Gráfico de Mapa de PowerPoint | Pasos: Crear Gráfico de Mapa de Presentación de PowerPoint

Este código PHP te muestra cómo crear un gráfico de mapa:

  $pres = new Presentation();
  try {
    $chart = $pres->getSlides()->get_Item(0)->getShapes()->addChart(ChartType::Map, 50, 50, 500, 400);
    $pres->save("mapChart.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Creando Gráficos Combinados

Un gráfico combinado (o gráfico combo) es un gráfico que combina dos o más gráficos en un solo gráfico. Tal gráfico te permite resaltar, comparar o revisar las diferencias entre dos (o más) conjuntos de datos. De esta manera, ves la relación (si la hay) entre los conjuntos de datos.

combination-chart-ppt

Este código PHP te muestra cómo crear un gráfico combinado en PowerPoint:


Actualizar Gráficos

Pasos: Actualizar Gráfico de PowerPoint | Pasos: Actualizar Gráfico de Presentación | Pasos: Actualizar Gráfico de Presentación de PowerPoint

  1. Instancia una clase Presentation que representa la presentación que contiene el gráfico que deseas actualizar.
  2. Obtén la referencia de una diapositiva usando su índice.
  3. Recorre todas las formas para encontrar el gráfico deseado.
  4. Accede a la hoja de trabajo de datos del gráfico.
  5. Modifica los datos de la serie del gráfico cambiando los valores de las series.
  6. Agrega una nueva serie y pobla los datos en ella.
  7. Escribe la presentación modificada como un archivo PPTX.

Este código PHP te muestra cómo actualizar un gráfico:

  $pres = new Presentation();
  try {
    # Accede a la primera diapositiva
    $sld = $pres->getSlides()->get_Item(0);
    # Obtiene el gráfico con datos predeterminados
    $chart = $sld->getShapes()->get_Item(0);
    # Estableciendo el índice de la hoja de datos del gráfico
    $defaultWorksheetIndex = 0;
    # Obteniendo la hoja de trabajo de datos del gráfico
    $fact = $chart->getChartData()->getChartDataWorkbook();
    # Cambiando el nombre de la categoría del gráfico
    $fact->getCell($defaultWorksheetIndex, 1, 0, "Categoría Modificada 1");
    $fact->getCell($defaultWorksheetIndex, 2, 0, "Categoría Modificada 2");
    # Toma la primera serie del gráfico
    $series = $chart->getChartData()->getSeries()->get_Item(0);
    # Ahora actualizando los datos de la serie
    $fact->getCell($defaultWorksheetIndex, 0, 1, "Nueva_Serie1");// Modificando el nombre de la serie

    $series->getDataPoints()->get_Item(0)->getValue()->setData(90);
    $series->getDataPoints()->get_Item(1)->getValue()->setData(123);
    $series->getDataPoints()->get_Item(2)->getValue()->setData(44);
    # Toma la segunda serie del gráfico
    $series = $chart->getChartData()->getSeries()->get_Item(1);
    # Ahora actualizando los datos de la serie
    $fact->getCell($defaultWorksheetIndex, 0, 2, "Nueva_Serie2");// Modificando el nombre de la serie

    $series->getDataPoints()->get_Item(0)->getValue()->setData(23);
    $series->getDataPoints()->get_Item(1)->getValue()->setData(67);
    $series->getDataPoints()->get_Item(2)->getValue()->setData(99);
    # Ahora, agregando una nueva serie
    $chart->getChartData()->getSeries()->add($fact->getCell($defaultWorksheetIndex, 0, 3, "Serie 3"), $chart->getType());
    # Toma la tercera serie del gráfico
    $series = $chart->getChartData()->getSeries()->get_Item(2);
    # Ahora poblando los datos de la serie
    $series->getDataPoints()->addDataPointForBarSeries($fact->getCell($defaultWorksheetIndex, 1, 3, 20));
    $series->getDataPoints()->addDataPointForBarSeries($fact->getCell($defaultWorksheetIndex, 2, 3, 50));
    $series->getDataPoints()->addDataPointForBarSeries($fact->getCell($defaultWorksheetIndex, 3, 3, 30));
    $chart->setType(ChartType::ClusteredCylinder);
    # Guarda la presentación con el gráfico
    $pres->save("AsposeChartModified_out.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Estableciendo el Rango de Datos para Gráficos

Para establecer el rango de datos para un gráfico, haz lo siguiente:

  1. Instancia una clase Presentation que representa la presentación que contiene el gráfico.
  2. Obtén la referencia de una diapositiva a través de su índice.
  3. Recorre todas las formas para encontrar el gráfico deseado.
  4. Accede a los datos del gráfico y establece el rango.
  5. Guarda la presentación modificada como un archivo PPTX.

Este código PHP te muestra cómo establecer el rango de datos para un gráfico:

  $pres = new Presentation();
  try {
    $slide = $pres->getSlides()->get_Item(0);
    $chart = $slide->getShapes()->get_Item(0);
    $chart->getChartData()->setRange("Hoja1!A1:B4");
    $pres->save("SetDataRange_out.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Usando Marcadores Predeterminados en Gráficos

Cuando usas un marcador predeterminado en gráficos, cada serie de gráficos recibe diferentes símbolos de marcadores predeterminados automáticamente.

Este código PHP te muestra cómo establecer un marcador de serie de gráfico automáticamente:

  $pres = new Presentation();
  try {
    $slide = $pres->getSlides()->get_Item(0);
    $chart = $slide->getShapes()->addChart(ChartType::LineWithMarkers, 10, 10, 400, 400);
    $chart->getChartData()->getSeries()->clear();
    $chart->getChartData()->getCategories()->clear();
    $fact = $chart->getChartData()->getChartDataWorkbook();
    $chart->getChartData()->getSeries()->add($fact->getCell(0, 0, 1, "Serie 1"), $chart->getType());
    $series = $chart->getChartData()->getSeries()->get_Item(0);
    $chart->getChartData()->getCategories()->add($fact->getCell(0, 1, 0, "C1"));
    $series->getDataPoints()->addDataPointForLineSeries($fact->getCell(0, 1, 1, 24));
    $chart->getChartData()->getCategories()->add($fact->getCell(0, 2, 0, "C2"));
    $series->getDataPoints()->addDataPointForLineSeries($fact->getCell(0, 2, 1, 23));
    $chart->getChartData()->getCategories()->add($fact->getCell(0, 3, 0, "C3"));
    $series->getDataPoints()->addDataPointForLineSeries($fact->getCell(0, 3, 1, -10));
    $chart->getChartData()->getCategories()->add($fact->getCell(0, 4, 0, "C4"));
    $series->getDataPoints()->addDataPointForLineSeries($fact->getCell(0, 4, 1, null));
    $chart->getChartData()->getSeries()->add($fact->getCell(0, 0, 2, "Serie 2"), $chart->getType());
    # Toma la segunda serie del gráfico
    $series2 = $chart->getChartData()->getSeries()->get_Item(1);
    # Ahora poblando los datos de la serie
    $series2->getDataPoints()->addDataPointForLineSeries($fact->getCell(0, 1, 2, 30));
    $series2->getDataPoints()->addDataPointForLineSeries($fact->getCell(0, 2, 2, 10));
    $series2->getDataPoints()->addDataPointForLineSeries($fact