Créer ou mettre à jour des graphiques de présentation PowerPoint en PHP
Vue d’ensemble
Cet article fournit un guide complet sur la façon de créer et de personnaliser des graphiques à l’aide d’Aspose.Slides pour PHP via Java. Vous apprendrez comment ajouter programmatiquement un graphique à une diapositive, le remplir avec des données et appliquer diverses options de formatage pour répondre à vos exigences de conception spécifiques. Tout au long de l’article, des exemples de code détaillés illustrent chaque étape, depuis l’initialisation de la présentation et de l’objet graphique jusqu’à la configuration des séries, des axes et des légendes. En suivant ce guide, vous acquerrez une solide compréhension de l’intégration de la génération dynamique de graphiques dans vos applications PHP, simplifiant le processus de création de présentations basées sur les données.
Créer un graphique
Les graphiques aident les utilisateurs à visualiser rapidement les données et à obtenir des insights qui ne sont pas immédiatement évidents à partir d’un tableau ou d’une feuille de calcul.
Pourquoi créer des graphiques ?
L’utilisation de graphiques vous permet de :
- agréger, condenser ou résumer de grandes quantités de données sur une seule diapositive d’une présentation ;
- mettre en évidence des motifs et des tendances dans les données ;
- déduire la direction et l’élan des données au fil du temps ou par rapport à une unité de mesure spécifique ;
- repérer les valeurs aberrantes, les anomalies, les écarts, les erreurs et les données non sensées ;
- communiquer ou présenter des données complexes.
Dans PowerPoint, vous pouvez créer des graphiques via la fonction Insert, qui propose des modèles pour concevoir de nombreux types de graphiques. Avec Aspose.Slides, vous pouvez créer à la fois des graphiques standards (basés sur des types de graphiques populaires) et des graphiques personnalisés.
Note
Utilisez l’énumération ChartType dans l’espace de noms aspose\slides. Les valeurs de cette énumération correspondent à différents types de graphiques.Créer des graphiques à colonnes groupées
Cet exemple utilise addChart pour créer un graphique à colonnes groupées qui compare deux séries sur trois catégories. Les séries utilisent des remplissages rouge et vert, et les libellés individuels affichent les noms des catégories, les noms des séries et les valeurs. L’index de feuille de calcul 0 fait référence à la première feuille du classeur de graphique intégré.
use aspose\slides\ChartType;
use aspose\slides\FillType;
use aspose\slides\NullableBool;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try
{
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::ClusteredColumn, 20, 20, 500, 300);
$chart->getChartTitle()->addTextFrameForOverriding("Sample Title");
$chart->getChartTitle()->getTextFrameForOverriding()->getTextFrameFormat()->setCenterText(NullableBool::True);
$chart->getChartTitle()->setHeight(20);
$chart->setTitle(true);
$workbook = $chart->getChartData()->getChartDataWorkbook();
$worksheetIndex = 0;
$chart->getChartData()->getSeries()->clear();
$chart->getChartData()->getCategories()->clear();
$seriesNameCell = $workbook->getCell($worksheetIndex, 0, 1, "Series 1");
$chart->getChartData()->getSeries()->add($seriesNameCell, $chart->getType());
$seriesNameCell = $workbook->getCell($worksheetIndex, 0, 2, "Series 2");
$chart->getChartData()->getSeries()->add($seriesNameCell, $chart->getType());
$categoryCell = $workbook->getCell($worksheetIndex, 1, 0, "Category 1");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell($worksheetIndex, 2, 0, "Category 2");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell($worksheetIndex, 3, 0, "Category 3");
$chart->getChartData()->getCategories()->add($categoryCell);
$series = $chart->getChartData()->getSeries()->get_Item(0);
$valueCell = $workbook->getCell($worksheetIndex, 1, 1, 20);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, 2, 1, 50);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, 3, 1, 30);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$series->getFormat()->getFill()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 255, 0, 0);
$series->getFormat()->getFill()->getSolidFillColor()->setColor($color);
$series = $chart->getChartData()->getSeries()->get_Item(1);
$valueCell = $workbook->getCell($worksheetIndex, 1, 2, 30);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, 2, 2, 10);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, 3, 2, 60);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$series->getFormat()->getFill()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 0, 128, 0);
$series->getFormat()->getFill()->getSolidFillColor()->setColor($color);
$label = $series->getDataPoints()->get_Item(0)->getLabel();
$label->getDataLabelFormat()->setShowCategoryName(true);
$label = $series->getDataPoints()->get_Item(1)->getLabel();
$label->getDataLabelFormat()->setShowSeriesName(true);
$label = $series->getDataPoints()->get_Item(2)->getLabel();
$label->getDataLabelFormat()->setShowValue(true);
$label->getDataLabelFormat()->setShowSeriesName(true);
$label->getDataLabelFormat()->setSeparator("/");
$presentation->save("AsposeChart.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
Le résultat :

Créer des graphiques en nuage de points
Les graphiques en nuage de points (également appelés diagrammes de dispersion ou graphiques x‑y) sont souvent utilisés pour rechercher des motifs ou démontrer des corrélations entre deux variables.
Utilisez un graphique en nuage de points lorsque :
- Vous disposez de données numériques appariées.
- Vous avez deux variables qui s’associent bien.
- Vous voulez déterminer si les deux variables sont liées.
- Vous avez une variable indépendante qui possède plusieurs valeurs pour une variable dépendante.
Cet exemple trace deux ensembles de valeurs x‑y. La première série utilise des lignes droites avec des marqueurs en forme d’étoile, tandis que la seconde utilise des lignes lisses avec des marqueurs circulaires ; les deux utilisent une taille de marqueur de 10, configurée avec setSize. La méthode setSymbol contrôle la forme du marqueur.
use aspose\slides\ChartType;
use aspose\slides\MarkerStyleType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try
{
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::ScatterWithSmoothLines, 20, 20, 500, 300);
$workbook = $chart->getChartData()->getChartDataWorkbook();
$worksheetIndex = 0;
$chart->getChartData()->getSeries()->clear();
$seriesNameCell = $workbook->getCell($worksheetIndex, 1, 1, "Series 1");
$chart->getChartData()->getSeries()->add($seriesNameCell, $chart->getType());
$seriesNameCell = $workbook->getCell($worksheetIndex, 1, 3, "Series 2");
$chart->getChartData()->getSeries()->add($seriesNameCell, $chart->getType());
$series = $chart->getChartData()->getSeries()->get_Item(0);
$xValueCell = $workbook->getCell($worksheetIndex, 2, 1, 1);
$yValueCell = $workbook->getCell($worksheetIndex, 2, 2, 3);
$series->getDataPoints()->addDataPointForScatterSeries($xValueCell, $yValueCell);
$xValueCell = $workbook->getCell($worksheetIndex, 3, 1, 2);
$yValueCell = $workbook->getCell($worksheetIndex, 3, 2, 10);
$series->getDataPoints()->addDataPointForScatterSeries($xValueCell, $yValueCell);
$series->setType(ChartType::ScatterWithStraightLinesAndMarkers);
$series->getMarker()->setSize(10);
$series->getMarker()->setSymbol(MarkerStyleType::Star);
$series = $chart->getChartData()->getSeries()->get_Item(1);
$xValueCell = $workbook->getCell($worksheetIndex, 2, 3, 5);
$yValueCell = $workbook->getCell($worksheetIndex, 2, 4, 2);
$series->getDataPoints()->addDataPointForScatterSeries($xValueCell, $yValueCell);
$xValueCell = $workbook->getCell($worksheetIndex, 3, 3, 3);
$yValueCell = $workbook->getCell($worksheetIndex, 3, 4, 1);
$series->getDataPoints()->addDataPointForScatterSeries($xValueCell, $yValueCell);
$xValueCell = $workbook->getCell($worksheetIndex, 4, 3, 2);
$yValueCell = $workbook->getCell($worksheetIndex, 4, 4, 2);
$series->getDataPoints()->addDataPointForScatterSeries($xValueCell, $yValueCell);
$xValueCell = $workbook->getCell($worksheetIndex, 5, 3, 5);
$yValueCell = $workbook->getCell($worksheetIndex, 5, 4, 1);
$series->getDataPoints()->addDataPointForScatterSeries($xValueCell, $yValueCell);
$series->getMarker()->setSize(10);
$series->getMarker()->setSymbol(MarkerStyleType::Circle);
$presentation->save("AsposeChart.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
Le résultat :

Créer des graphiques circulaires
Les graphiques circulaires sont surtout utiles pour montrer la relation partie‑à‑tout dans les données, en particulier lorsque les données contiennent des libellés catégoriques avec des valeurs numériques. Cependant, si vos données comportent de nombreuses parties ou libellés, vous pourriez envisager d’utiliser un graphique à barres à la place.
Cet exemple crée un graphique circulaire avec trois valeurs trimestrielles. Chaque tranche possède un remplissage et une bordure personnalisés, et les libellés affichent différentes combinaisons de valeurs, de pourcentages et d’informations de séries. La méthode setFirstSliceAngle définit la première tranche à 180 degrés.
use aspose\slides\ChartType;
use aspose\slides\FillType;
use aspose\slides\LineDashStyle;
use aspose\slides\LineStyle;
use aspose\slides\NullableBool;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try
{
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::Pie, 20, 20, 500, 300);
$chart->getChartTitle()->addTextFrameForOverriding("Sample Title");
$chart->getChartTitle()->getTextFrameForOverriding()->getTextFrameFormat()->setCenterText(NullableBool::True);
$chart->getChartTitle()->setHeight(20);
$chart->setTitle(true);
$chart->getChartData()->getSeries()->get_Item(0)->getLabels()->getDefaultDataLabelFormat()->setShowValue(true);
$workbook = $chart->getChartData()->getChartDataWorkbook();
$worksheetIndex = 0;
$chart->getChartData()->getSeries()->clear();
$chart->getChartData()->getCategories()->clear();
$categoryCell = $workbook->getCell(0, 1, 0, "1st Qtr");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, 2, 0, "2nd Qtr");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, 3, 0, "3rd Qtr");
$chart->getChartData()->getCategories()->add($categoryCell);
$seriesNameCell = $workbook->getCell(0, 0, 1, "Series 1");
$series = $chart->getChartData()->getSeries()->add($seriesNameCell, $chart->getType());
$valueCell = $workbook->getCell($worksheetIndex, 1, 1, 20);
$series->getDataPoints()->addDataPointForPieSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, 2, 1, 50);
$series->getDataPoints()->addDataPointForPieSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, 3, 1, 30);
$series->getDataPoints()->addDataPointForPieSeries($valueCell);
$chart->getChartData()->getSeriesGroups()->get_Item(0)->setColorVaried(true);
$firstSlice = $series->getDataPoints()->get_Item(0);
$firstSlice->getFormat()->getFill()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 0, 255, 255);
$firstSlice->getFormat()->getFill()->getSolidFillColor()->setColor($color);
$firstSlice->getFormat()->getLine()->getFillFormat()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 128, 128, 128);
$firstSlice->getFormat()->getLine()->getFillFormat()->getSolidFillColor()->setColor($color);
$firstSlice->getFormat()->getLine()->setWidth(3.0);
$firstSlice->getFormat()->getLine()->setStyle(LineStyle::ThinThick);
$firstSlice->getFormat()->getLine()->setDashStyle(LineDashStyle::LargeDash);
$secondSlice = $series->getDataPoints()->get_Item(1);
$secondSlice->getFormat()->getFill()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 165, 42, 42);
$secondSlice->getFormat()->getFill()->getSolidFillColor()->setColor($color);
$secondSlice->getFormat()->getLine()->getFillFormat()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 0, 0, 255);
$secondSlice->getFormat()->getLine()->getFillFormat()->getSolidFillColor()->setColor($color);
$secondSlice->getFormat()->getLine()->setWidth(3.0);
$secondSlice->getFormat()->getLine()->setStyle(LineStyle::Single);
$secondSlice->getFormat()->getLine()->setDashStyle(LineDashStyle::LargeDashDot);
$thirdSlice = $series->getDataPoints()->get_Item(2);
$thirdSlice->getFormat()->getFill()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 255, 127, 80);
$thirdSlice->getFormat()->getFill()->getSolidFillColor()->setColor($color);
$thirdSlice->getFormat()->getLine()->getFillFormat()->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 255, 0, 0);
$thirdSlice->getFormat()->getLine()->getFillFormat()->getSolidFillColor()->setColor($color);
$thirdSlice->getFormat()->getLine()->setWidth(2.0);
$thirdSlice->getFormat()->getLine()->setStyle(LineStyle::ThinThin);
$thirdSlice->getFormat()->getLine()->setDashStyle(LineDashStyle::LargeDashDotDot);
$firstLabel = $series->getDataPoints()->get_Item(0)->getLabel();
$firstLabel->getDataLabelFormat()->setShowValue(true);
$secondLabel = $series->getDataPoints()->get_Item(1)->getLabel();
$secondLabel->getDataLabelFormat()->setShowValue(true);
$secondLabel->getDataLabelFormat()->setShowLegendKey(true);
$secondLabel->getDataLabelFormat()->setShowPercentage(true);
$thirdLabel = $series->getDataPoints()->get_Item(2)->getLabel();
$thirdLabel->getDataLabelFormat()->setShowSeriesName(true);
$thirdLabel->getDataLabelFormat()->setShowPercentage(true);
$series->getLabels()->getDefaultDataLabelFormat()->setShowLeaderLines(true);
$chart->getChartData()->getSeriesGroups()->get_Item(0)->setFirstSliceAngle(180);
$presentation->save("PieChart.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
Le résultat :

Pour améliorer la lisibilité des libellés situés à l’extérieur du graphique circulaire, consultez Format Leader Lines pour un exemple qui positionne les libellés et personnalise la couleur, la largeur, la transparence et le style de tiret des lignes.
Créer des graphiques en courbes
Les graphiques en courbes (également appelés graphiques linéaires) sont surtout appropriés lorsque vous souhaitez montrer des variations de valeur dans le temps. Avec un graphique en courbes, vous pouvez comparer un grand nombre de données en une fois, suivre les changements et les tendances au fil du temps, mettre en évidence des anomalies dans les séries de données, etc.
Cet exemple utilise addChart pour créer un graphique en courbes avec les séries et catégories par défaut, puis enregistre la présentation au format PPTX.
use aspose\slides\ChartType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try
{
$slide = $presentation->getSlides()->get_Item(0);
$lineChart = $slide->getShapes()->addChart(ChartType::Line, 20, 20, 500, 300);
$presentation->save("lineChart.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
Par défaut, les points d’un graphique en courbes sont reliés par des lignes droites continues. Si vous souhaitez que les points soient reliés par des tirets, appelez setDashStyle avec une valeur provenant de LineDashStyle :
use aspose\slides\ChartType;
use aspose\slides\LineDashStyle;
use aspose\slides\Presentation;
$presentation = new Presentation();
try
{
$slide = $presentation->getSlides()->get_Item(0);
$lineChart = $slide->getShapes()->addChart(ChartType::Line, 20, 20, 500, 300);
for ($i = 0; $i < java_values($lineChart->getChartData()->getSeries()->size()); $i++)
{
$series = $lineChart->getChartData()->getSeries()->get_Item($i);
$series->getFormat()->getLine()->setDashStyle(LineDashStyle::Dash);
}
}
finally
{
$presentation->dispose();
}
Le résultat :

Créer des graphiques en carte d’arbre
Les graphiques en carte d’arbre sont surtout utiles pour les données de ventes lorsque vous voulez montrer la taille relative des catégories de données et attirer rapidement l’attention sur les éléments qui contribuent le plus dans chaque catégorie.
Cet exemple crée une carte d’arbre avec huit feuilles regroupées en quatre tiges et deux branches. La méthode setGroupingItem attribue les tiges au niveau de groupement 1 et les branches au niveau 2. Les valeurs déterminent les tailles relatives des rectangles, tandis que les libellés de catégories et les libellés parentaux superposés identifient la hiérarchie.
use aspose\slides\ChartType;
use aspose\slides\ParentLabelLayoutType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try
{
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::Treemap, 20, 20, 500, 300);
$chart->getChartData()->getCategories()->clear();
$chart->getChartData()->getSeries()->clear();
$workbook = $chart->getChartData()->getChartDataWorkbook();
$workbook->clear(0);
// Branche 1
$categoryCell = $workbook->getCell(0, "C1", "Leaf1");
$leaf = $chart->getChartData()->getCategories()->add($categoryCell);
$leaf->getGroupingLevels()->setGroupingItem(1, "Stem1");
$leaf->getGroupingLevels()->setGroupingItem(2, "Branch1");
$categoryCell = $workbook->getCell(0, "C2", "Leaf2");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, "C3", "Leaf3");
$leaf = $chart->getChartData()->getCategories()->add($categoryCell);
$leaf->getGroupingLevels()->setGroupingItem(1, "Stem2");
$categoryCell = $workbook->getCell(0, "C4", "Leaf4");
$chart->getChartData()->getCategories()->add($categoryCell);
// Branche 2
$categoryCell = $workbook->getCell(0, "C5", "Leaf5");
$leaf = $chart->getChartData()->getCategories()->add($categoryCell);
$leaf->getGroupingLevels()->setGroupingItem(1, "Stem3");
$leaf->getGroupingLevels()->setGroupingItem(2, "Branch2");
$categoryCell = $workbook->getCell(0, "C6", "Leaf6");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, "C7", "Leaf7");
$leaf = $chart->getChartData()->getCategories()->add($categoryCell);
$leaf->getGroupingLevels()->setGroupingItem(1, "Stem4");
$categoryCell = $workbook->getCell(0, "C8", "Leaf8");
$chart->getChartData()->getCategories()->add($categoryCell);
$series = $chart->getChartData()->getSeries()->add(ChartType::Treemap);
$series->getLabels()->getDefaultDataLabelFormat()->setShowCategoryName(true);
$valueCell = $workbook->getCell(0, "D1", 4);
$series->getDataPoints()->addDataPointForTreemapSeries($valueCell);
$valueCell = $workbook->getCell(0, "D2", 5);
$series->getDataPoints()->addDataPointForTreemapSeries($valueCell);
$valueCell = $workbook->getCell(0, "D3", 3);
$series->getDataPoints()->addDataPointForTreemapSeries($valueCell);
$valueCell = $workbook->getCell(0, "D4", 6);
$series->getDataPoints()->addDataPointForTreemapSeries($valueCell);
$valueCell = $workbook->getCell(0, "D5", 9);
$series->getDataPoints()->addDataPointForTreemapSeries($valueCell);
$valueCell = $workbook->getCell(0, "D6", 9);
$series->getDataPoints()->addDataPointForTreemapSeries($valueCell);
$valueCell = $workbook->getCell(0, "D7", 4);
$series->getDataPoints()->addDataPointForTreemapSeries($valueCell);
$valueCell = $workbook->getCell(0, "D8", 3);
$series->getDataPoints()->addDataPointForTreemapSeries($valueCell);
$series->setParentLabelLayout(ParentLabelLayoutType::Overlapping);
$presentation->save("Treemap.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
Le résultat :

Créer des graphiques en cascade
Un graphique en cascade montre comment les variations positives et négatives contribuent à une valeur finale. Par exemple, le détail d’un profit peut commencer avec le chiffre d’affaires, soustraire les coûts et ajouter d’autres revenus. Les colonnes de variation flottent entre les valeurs cumulées précédentes et nouvelles, tandis que les colonnes totales s’étendent de zéro à la valeur accumulée.
L’exemple suivant utilise des montants en milliers de dollars américains :
| Catégorie | Valeur du classeur | Type de colonne |
|---|---|---|
| Chiffre d’affaires | 1000 | Augmentation |
| Coût des ventes | -400 | Diminution |
| Marge brute | 600 | Total intermédiaire |
| Charges d’exploitation | -200 | Diminution |
| Autres revenus | 50 | Augmentation |
| Résultat net | 450 | Total final |
Pour marquer un point comme total intermédiaire ou final, appelez sa méthode setSetAsTotal avec true. Fournissez le montant réellement accumulé dans la cellule du classeur correspondante : 600 pour la marge brute (1000 - 400) et 450 pour le résultat net (600 - 200 + 50). La méthode marque la colonne comme total ; elle ne calcule ni ne remplit la valeur de la cellule. N’utilisez pas zéro comme espace réservé ni ne fournissez une autre variation pour un point total. Une colonne totale affiche la valeur accumulée sans l’ajouter à nouveau à la valeur courante.
Cet exemple complet en PHP crée un graphique en utilisant le membre Waterfall de ChartType, efface les données par défaut et remplit le classeur intégré. L’index de feuille de calcul 0 sélectionne la première feuille ; la colonne A contient les noms de catégories et la colonne B contient les valeurs. Chaque cellule de valeur est ajoutée avec addDataPointForWaterfallSeries. Les indices de points basés sur zéro 2 et 5 identifient respectivement les totaux intermédiaires et finaux. L’appel à setShowValue avec true affiche les montants sur les colonnes. Aucun classeur ou présentation d’entrée n’est requis.
use aspose\slides\ChartType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try
{
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::Waterfall, 20, 20, 680, 200);
$chart->setTitle(true);
$chart->getChartTitle()->addTextFrameForOverriding("Profit breakdown (USD thousands)");
$chart->getChartTitle()->setOverlay(false);
$chart->setLegend(false);
$chart->getChartData()->getSeries()->clear();
$chart->getChartData()->getCategories()->clear();
$workbook = $chart->getChartData()->getChartDataWorkbook();
$worksheetIndex = 0;
$workbook->clear($worksheetIndex);
$seriesNameCell = $workbook->getCell($worksheetIndex, 0, 1, "Profit");
$series = $chart->getChartData()->getSeries()->add($seriesNameCell, ChartType::Waterfall);
$categories = [ "Revenue", "Cost of sales", "Gross profit", "Operating expenses", "Other income", "Net profit" ];
$values = [ 1000, -400, 600, -200, 50, 450 ];
for ($i = 0; $i < count($categories); $i++)
{
$categoryCell = $workbook->getCell($worksheetIndex, $i + 1, 0, $categories[$i]);
$chart->getChartData()->getCategories()->add($categoryCell);
$valueCell = $workbook->getCell($worksheetIndex, $i + 1, 1, $values[$i]);
$series->getDataPoints()->addDataPointForWaterfallSeries($valueCell);
}
// Le troisième et le sixième points représentent des totaux, pas des changements supplémentaires.
$series->getDataPoints()->get_Item(2)->setSetAsTotal(true);
$series->getDataPoints()->get_Item(5)->setSetAsTotal(true);
$series->setShowConnectorLines(true);
$series->getLabels()->getDefaultDataLabelFormat()->setShowValue(true);
$presentation->save("WaterfallChart.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
Appelez la méthode de niveau série setShowConnectorLines avec true pour afficher les lignes reliant les colonnes consécutives et faciliter le suivi de la valeur courante. Pour masquer ces lignes, remplacez l’appel de méthode dans l’exemple par $series->setShowConnectorLines(false); avant l’enregistrement. Cela ne change que la visibilité des lignes, pas les données ou les totaux.
La présentation enregistrée montre une marge brute de 600 et un résultat net de 450, les deux totaux partant de zéro :

Créer des graphiques boursiers
Les graphiques boursiers servent à afficher des données financières telles que les prix d’ouverture, haut, bas et de clôture, aidant à analyser les tendances du marché et la volatilité. Ils offrent des insights essentiels sur la performance des actions, aidant investisseurs et analystes à prendre des décisions éclairées.
Cet exemple crée un graphique ouvert‑haut‑bas‑clôture avec quatre séries dans cet ordre et trois catégories. La méthode setUpDownBars active les barres haut/bas, et getHiLowLinesFormat contrôle les lignes haut‑bas qui montrent les fourchettes de prix, tandis que les lignes des séries individuelles et les petites lignes de grille horizontales sont masquées.
Le gestionnaire retourné par getUpDownBars expose des objets de formatage séparés via getUpBarsFormat et getDownBarsFormat. Utilisez les méthodes getFill et getLine de chaque objet pour définir indépendamment le remplissage et le contour. Cet exemple utilise des barres vertes avec des contours vert foncé pour les intervalles haussiers et des barres orange‑rouge avec des contours rouge foncé pour les intervalles baissiers.
Fournissez des valeurs numériques pour les quatre séries à chaque catégorie, le Haut et le Bas englobant l’Ouverture et la Clôture. Les barres comparent la Clôture à l’Ouverture au sein de la même catégorie, pas à la catégorie précédente : A chute de 72 à 25, tandis que B monte de 25 à 38 et C monte de 38 à 50. Des valeurs d’Ouverture et de Clôture égales ne produisent aucun intervalle rempli visible. Les barres haut/bas couvrent Ouverture‑Clôture ; les lignes haut‑bas couvrent Bas‑Haut. Ces barres appartiennent au groupe de séries et ne sont pas des séries de graphiques à barres ordinaires.
Ce formatage fonctionne également avec les graphiques Line and LineWithMarkers contenant au moins deux séries dans le même groupe et des valeurs numériques correspondantes pour chaque catégorie. Pour ces graphiques linéaires non empilés, les barres haut/bas comparent la première et la dernière série : une dernière valeur plus élevée produit une barre haute, une dernière valeur plus basse produit une barre basse. Inverser ces séries inverse la classification. L’exemple ci‑dessous utilise OpenHighLowClose ; ne supposez pas que d’autres variantes boursières, linéaires empilées ou 3D utilisent la même organisation des données ou la même interprétation des intervalles.
use aspose\slides\ChartType;
use aspose\slides\FillType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try
{
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::OpenHighLowClose, 20, 20, 500, 150, false);
$workbook = $chart->getChartData()->getChartDataWorkbook();
$categoryCell = $workbook->getCell(0, 1, 0, "A");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, 2, 0, "B");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, 3, 0, "C");
$chart->getChartData()->getCategories()->add($categoryCell);
$seriesNameCell = $workbook->getCell(0, 0, 1, "Open");
$chart->getChartData()->getSeries()->add($seriesNameCell, ChartType::OpenHighLowClose);
$seriesNameCell = $workbook->getCell(0, 0, 2, "High");
$chart->getChartData()->getSeries()->add($seriesNameCell, ChartType::OpenHighLowClose);
$seriesNameCell = $workbook->getCell(0, 0, 3, "Low");
$chart->getChartData()->getSeries()->add($seriesNameCell, ChartType::OpenHighLowClose);
$seriesNameCell = $workbook->getCell(0, 0, 4, "Close");
$chart->getChartData()->getSeries()->add($seriesNameCell, ChartType::OpenHighLowClose);
$series = $chart->getChartData()->getSeries()->get_Item(0);
$valueCell = $workbook->getCell(0, 1, 1, 72);
$series->getDataPoints()->addDataPointForStockSeries($valueCell);
$valueCell = $workbook->getCell(0, 2, 1, 25);
$series->getDataPoints()->addDataPointForStockSeries($valueCell);
$valueCell = $workbook->getCell(0, 3, 1, 38);
$series->getDataPoints()->addDataPointForStockSeries($valueCell);
$series = $chart->getChartData()->getSeries()->get_Item(1);
$valueCell = $workbook->getCell(0, 1, 2, 172);
$series->getDataPoints()->addDataPointForStockSeries($valueCell);
$valueCell = $workbook->getCell(0, 2, 2, 57);
$series->getDataPoints()->addDataPointForStockSeries($valueCell);
$valueCell = $workbook->getCell(0, 3, 2, 57);
$series->getDataPoints()->addDataPointForStockSeries($valueCell);
$series = $chart->getChartData()->getSeries()->get_Item(2);
$valueCell = $workbook->getCell(0, 1, 3, 12);
$series->getDataPoints()->addDataPointForStockSeries($valueCell);
$valueCell = $workbook->getCell(0, 2, 3, 12);
$series->getDataPoints()->addDataPointForStockSeries($valueCell);
$valueCell = $workbook->getCell(0, 3, 3, 13);
$series->getDataPoints()->addDataPointForStockSeries($valueCell);
$series = $chart->getChartData()->getSeries()->get_Item(3);
$valueCell = $workbook->getCell(0, 1, 4, 25);
$series->getDataPoints()->addDataPointForStockSeries($valueCell);
$valueCell = $workbook->getCell(0, 2, 4, 38);
$series->getDataPoints()->addDataPointForStockSeries($valueCell);
$valueCell = $workbook->getCell(0, 3, 4, 50);
$series->getDataPoints()->addDataPointForStockSeries($valueCell);
$upDownBars = $chart->getChartData()->getSeriesGroups()->get_Item(0)->getUpDownBars();
$upDownBars->setUpDownBars(true);
$upDownBars->getUpBarsFormat()->getFill()->setFillType(FillType::Solid);
$upDownBars->getUpBarsFormat()->getFill()->getSolidFillColor()->setColor(new Java("java.awt.Color", 50, 205, 50));
$upDownBars->getUpBarsFormat()->getLine()->getFillFormat()->setFillType(FillType::Solid);
$upDownBars->getUpBarsFormat()->getLine()->getFillFormat()->getSolidFillColor()->setColor(new Java("java.awt.Color", 0, 100, 0));
$upDownBars->getUpBarsFormat()->getLine()->setWidth(2);
$upDownBars->getDownBarsFormat()->getFill()->setFillType(FillType::Solid);
$upDownBars->getDownBarsFormat()->getFill()->getSolidFillColor()->setColor(new Java("java.awt.Color", 255, 69, 0));
$upDownBars->getDownBarsFormat()->getLine()->getFillFormat()->setFillType(FillType::Solid);
$upDownBars->getDownBarsFormat()->getLine()->getFillFormat()->getSolidFillColor()->setColor(new Java("java.awt.Color", 139, 0, 0));
$upDownBars->getDownBarsFormat()->getLine()->setWidth(2);
$chart->getChartData()->getSeriesGroups()->get_Item(0)->getHiLowLinesFormat()->getLine()->getFillFormat()->setFillType(FillType::Solid);
for ($i = 0; $i < java_values($chart->getChartData()->getSeries()->size()); $i++)
{
$stockSeries = $chart->getChartData()->getSeries()->get_Item($i);
$stockSeries->getFormat()->getLine()->getFillFormat()->setFillType(FillType::NoFill);
}
$chart->getAxes()->getVerticalAxis()->getMinorGridLinesFormat()->getLine()->getFillFormat()->setFillType(FillType::NoFill);
$presentation->save("Stock-chart.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
Le résultat, exporté depuis PowerPoint :

Créer des graphiques à boîtes et moustaches
Les graphiques à boîtes et moustaches servent à afficher la distribution des données en résumant les mesures statistiques clés, telles que la médiane, les quartiles et les valeurs aberrantes potentielles. Ils sont particulièrement utiles dans l’analyse exploratoire des données et les études statistiques pour comprendre rapidement la variabilité des données et identifier d’éventuelles anomalies.
Cet exemple crée un graphique à boîtes et moustaches à partir de six valeurs. La méthode setQuartileMethod sélectionne le calcul quartile exclusif. L’exemple active également les lignes de moyenne, les marqueurs de moyenne, les points internes et les points aberrants.
use aspose\slides\ChartType;
use aspose\slides\Presentation;
use aspose\slides\QuartileMethodType;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try
{
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::BoxAndWhisker, 20, 20, 500, 300);
$chart->getChartData()->getCategories()->clear();
$chart->getChartData()->getSeries()->clear();
$workbook = $chart->getChartData()->getChartDataWorkbook();
$workbook->clear(0);
$categoryCell = $workbook->getCell(0, "A1", "Category 1");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, "A2", "Category 2");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, "A3", "Category 3");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, "A4", "Category 4");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, "A5", "Category 5");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, "A6", "Category 6");
$chart->getChartData()->getCategories()->add($categoryCell);
$series = $chart->getChartData()->getSeries()->add(ChartType::BoxAndWhisker);
$series->setQuartileMethod(QuartileMethodType::Exclusive);
$series->setShowMeanLine(true);
$series->setShowMeanMarkers(true);
$series->setShowInnerPoints(true);
$series->setShowOutlierPoints(true);
$valueCell = $workbook->getCell(0, "B1", 15);
$series->getDataPoints()->addDataPointForBoxAndWhiskerSeries($valueCell);
$valueCell = $workbook->getCell(0, "B2", 41);
$series->getDataPoints()->addDataPointForBoxAndWhiskerSeries($valueCell);
$valueCell = $workbook->getCell(0, "B3", 16);
$series->getDataPoints()->addDataPointForBoxAndWhiskerSeries($valueCell);
$valueCell = $workbook->getCell(0, "B4", 10);
$series->getDataPoints()->addDataPointForBoxAndWhiskerSeries($valueCell);
$valueCell = $workbook->getCell(0, "B5", 23);
$series->getDataPoints()->addDataPointForBoxAndWhiskerSeries($valueCell);
$valueCell = $workbook->getCell(0, "B6", 16);
$series->getDataPoints()->addDataPointForBoxAndWhiskerSeries($valueCell);
$presentation->save("BoxAndWhisker.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
Créer des graphiques en entonnoir
Les graphiques en entonnoir servent à visualiser des processus comportant des étapes séquentielles, où le volume de données diminue au fur et à mesure qu’il progresse d’une étape à la suivante. Ils sont particulièrement utiles pour analyser les taux de conversion, identifier les goulets d’étranglement et suivre l’efficacité des processus de vente ou de marketing.
Cet exemple utilise addChart pour ajouter un graphique en entonnoir à la première diapositive d’une présentation existante. Il remplace les données par défaut par six catégories et des valeurs allant de 50 à 500, puis enregistre la présentation mise à jour. La présentation d’entrée doit contenir au moins une diapositive.
use aspose\slides\ChartType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation("test.pptx");
try
{
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::Funnel, 50, 50, 500, 400);
$chart->getChartData()->getCategories()->clear();
$chart->getChartData()->getSeries()->clear();
$workbook = $chart->getChartData()->getChartDataWorkbook();
$workbook->clear(0);
$categoryCell = $workbook->getCell(0, "A1", "Category 1");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, "A2", "Category 2");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, "A3", "Category 3");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, "A4", "Category 4");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, "A5", "Category 5");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, "A6", "Category 6");
$chart->getChartData()->getCategories()->add($categoryCell);
$series = $chart->getChartData()->getSeries()->add(ChartType::Funnel);
$valueCell = $workbook->getCell(0, "B1", 50);
$series->getDataPoints()->addDataPointForFunnelSeries($valueCell);
$valueCell = $workbook->getCell(0, "B2", 100);
$series->getDataPoints()->addDataPointForFunnelSeries($valueCell);
$valueCell = $workbook->getCell(0, "B3", 200);
$series->getDataPoints()->addDataPointForFunnelSeries($valueCell);
$valueCell = $workbook->getCell(0, "B4", 300);
$series->getDataPoints()->addDataPointForFunnelSeries($valueCell);
$valueCell = $workbook->getCell(0, "B5", 400);
$series->getDataPoints()->addDataPointForFunnelSeries($valueCell);
$valueCell = $workbook->getCell(0, "B6", 500);
$series->getDataPoints()->addDataPointForFunnelSeries($valueCell);
$presentation->save("Funnel.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
Le résultat :

Créer des graphiques Sunburst
Les graphiques Sunburst servent à visualiser des données hiérarchiques, affichant les niveaux sous forme d’anneaux concentriques. Ils aident à illustrer les relations partie‑à‑tout et sont idéaux pour représenter des catégories et sous‑catégories imbriquées de manière claire et compacte.
Cet exemple crée un graphique Sunburst avec huit feuilles regroupées en quatre tiges et deux branches. La méthode setGroupingItem attribue les tiges au niveau de groupement 1 et les branches au niveau 2. Les libellés de catégorie identifient les segments, et les valeurs déterminent leurs tailles relatives.
use aspose\slides\ChartType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try
{
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::Sunburst, 20, 20, 500, 300);
$chart->getChartData()->getCategories()->clear();
$chart->getChartData()->getSeries()->clear();
$workbook = $chart->getChartData()->getChartDataWorkbook();
$workbook->clear(0);
// Branche 1
$categoryCell = $workbook->getCell(0, "C1", "Leaf1");
$leaf = $chart->getChartData()->getCategories()->add($categoryCell);
$leaf->getGroupingLevels()->setGroupingItem(1, "Stem1");
$leaf->getGroupingLevels()->setGroupingItem(2, "Branch1");
$categoryCell = $workbook->getCell(0, "C2", "Leaf2");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, "C3", "Leaf3");
$leaf = $chart->getChartData()->getCategories()->add($categoryCell);
$leaf->getGroupingLevels()->setGroupingItem(1, "Stem2");
$categoryCell = $workbook->getCell(0, "C4", "Leaf4");
$chart->getChartData()->getCategories()->add($categoryCell);
// Branche 2
$categoryCell = $workbook->getCell(0, "C5", "Leaf5");
$leaf = $chart->getChartData()->getCategories()->add($categoryCell);
$leaf->getGroupingLevels()->setGroupingItem(1, "Stem3");
$leaf->getGroupingLevels()->setGroupingItem(2, "Branch2");
$categoryCell = $workbook->getCell(0, "C6", "Leaf6");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, "C7", "Leaf7");
$leaf = $chart->getChartData()->getCategories()->add($categoryCell);
$leaf->getGroupingLevels()->setGroupingItem(1, "Stem4");
$categoryCell = $workbook->getCell(0, "C8", "Leaf8");
$chart->getChartData()->getCategories()->add($categoryCell);
$series = $chart->getChartData()->getSeries()->add(ChartType::Sunburst);
$series->getLabels()->getDefaultDataLabelFormat()->setShowCategoryName(true);
$valueCell = $workbook->getCell(0, "D1", 4);
$series->getDataPoints()->addDataPointForSunburstSeries($valueCell);
$valueCell = $workbook->getCell(0, "D2", 5);
$series->getDataPoints()->addDataPointForSunburstSeries($valueCell);
$valueCell = $workbook->getCell(0, "D3", 3);
$series->getDataPoints()->addDataPointForSunburstSeries($valueCell);
$valueCell = $workbook->getCell(0, "D4", 6);
$series->getDataPoints()->addDataPointForSunburstSeries($valueCell);
$valueCell = $workbook->getCell(0, "D5", 9);
$series->getDataPoints()->addDataPointForSunburstSeries($valueCell);
$valueCell = $workbook->getCell(0, "D6", 9);
$series->getDataPoints()->addDataPointForSunburstSeries($valueCell);
$valueCell = $workbook->getCell(0, "D7", 4);
$series->getDataPoints()->addDataPointForSunburstSeries($valueCell);
$valueCell = $workbook->getCell(0, "D8", 3);
$series->getDataPoints()->addDataPointForSunburstSeries($valueCell);
$presentation->save("Sunburst.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
Le résultat :

Créer des histogrammes
Les histogrammes montrent comment les valeurs numériques sont réparties sur des intervalles (bacs). Pour les rapports mensuels sur les temps de traitement des commandes, utilisez la même largeur de bac et les mêmes seuils afin de garder les intervalles cohérents et faciliter la comparaison des distributions.
Appelez setAggregationType sur l’axe horizontal avec un mode provenant de AxisAggregationType. setBinWidth s’applique uniquement à ByBinWidth ; setNumberOfBins s’applique uniquement à ByNumberOfBins. Utilisez Automatic pour laisser le graphique choisir les bacs.
Utiliser une largeur de bac fixe
Cet exemple regroupe les temps de traitement en intervalles de 10 minutes, avec des bacs séparés pour les temps ≤ 10 minutes et > 40 minutes. Activez ces bacs avec setUnderflowBin et setOverflowBin. Lors de la fourniture de seuils explicites via setUnderflowBin et setOverflowBin, appelez setAutomaticUnderflowBin et setAutomaticOverflowBin avec false.
use aspose\slides\AxisAggregationType;
use aspose\slides\ChartType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try
{
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::Histogram, 20, 20, 680, 200);
$chart->setLegend(false);
$chart->setTitle(false);
$chart->getChartData()->getCategories()->clear();
$chart->getChartData()->getSeries()->clear();
$workbook = $chart->getChartData()->getChartDataWorkbook();
$workbook->clear(0);
$series = $chart->getChartData()->getSeries()->add(ChartType::Histogram);
$values = [ 5, 10, 10, 11, 15, 20, 20, 21, 25, 30, 30, 31, 35, 40, 40, 41, 50 ];
for ($i = 0; $i < count($values); $i++)
{
$valueCell = $workbook->getCell(0, $i, 0, $values[$i]);
$series->getDataPoints()->addDataPointForHistogramSeries($valueCell);
}
$axis = $chart->getAxes()->getHorizontalAxis();
$axis->setAggregationType(AxisAggregationType::ByBinWidth);
$axis->setBinWidth(10);
$axis->setUnderflowBin(true);
$axis->setAutomaticUnderflowBin(false);
$axis->setUnderflowBin(10);
$axis->setOverflowBin(true);
$axis->setAutomaticOverflowBin(false);
$axis->setOverflowBin(40);
$presentation->save("Histogram-bin-width.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
La présentation affichée dans PowerPoint montre des comptes de bacs de 3, 4, 4, 4 et 2. Le bac de sous‑débordement comprend 5, 10, 10, son seuil est donc inclusif. Le bac de dépassement ne comprend que 41, 50, son seuil est exclusif ; les deux valeurs égales à 40 restent dans l’intervalle précédent. Les bacs intérieurs contiennent des valeurs supérieures à leur limite inférieure et inférieures ou égales à leur limite supérieure.

Spécifier le nombre de bacs
Pour un niveau de détail fixe plutôt que des intervalles fixes, demandez cinq bacs pour les mêmes données. Cet exemple laisse les bacs de sous‑débordement et de dépassement désactivés. Le graphique détermine la largeur à partir de la plage de données, de sorte que les limites peuvent changer entre les rapports.
use aspose\slides\AxisAggregationType;
use aspose\slides\ChartType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try
{
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::Histogram, 20, 20, 680, 200);
$chart->setLegend(false);
$chart->setTitle(false);
$chart->getChartData()->getCategories()->clear();
$chart->getChartData()->getSeries()->clear();
$workbook = $chart->getChartData()->getChartDataWorkbook();
$workbook->clear(0);
$series = $chart->getChartData()->getSeries()->add(ChartType::Histogram);
$values = [ 5, 10, 10, 11, 15, 20, 20, 21, 25, 30, 30, 31, 35, 40, 40, 41, 50 ];
for ($i = 0; $i < count($values); $i++)
{
$valueCell = $workbook->getCell(0, $i, 0, $values[$i]);
$series->getDataPoints()->addDataPointForHistogramSeries($valueCell);
}
$axis = $chart->getAxes()->getHorizontalAxis();
$axis->setAggregationType(AxisAggregationType::ByNumberOfBins);
$axis->setNumberOfBins(5);
$presentation->save("Histogram-bin-count.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
Les cinq bacs ont des comptes de 4, 4, 4, 4 et 1. Comparez cette distribution avec le résultat à largeur fixe ci‑dessus : les valeurs d’entrée sont identiques, mais les limites diffèrent.

Créer des graphiques radar
Les graphiques radar servent à afficher des données multivariées dans un format bidimensionnel, permettant une comparaison facile de plusieurs variables simultanément. Ils sont particulièrement utiles pour identifier des motifs, des forces et des faiblesses à travers plusieurs mesures ou attributs de performance.
Cet exemple utilise addChart pour créer un graphique radar avec les séries et catégories par défaut, puis enregistre la présentation au format PPTX.
use aspose\slides\ChartType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try
{
$slide = $presentation->getSlides()->get_Item(0);
$slide->getShapes()->addChart(ChartType::Radar, 20, 20, 500, 300);
$presentation->save("Radar-chart.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
Le résultat :

Créer des graphiques multi‑catégories
Les graphiques multi‑catégories servent à afficher des données impliquant plusieurs groupements catégoriques, vous permettant de comparer des valeurs à travers plusieurs dimensions simultanément. Ils sont particulièrement utiles lorsqu’il faut analyser des tendances et des relations au sein de jeux de données complexes et multicouches.
Cet exemple crée un graphique à colonnes groupées avec huit catégories disposées en quatre paires. La méthode setGroupingItem donne à chaque paire un libellé partagé au niveau de groupement 1, produisant un axe de catégorie avec à la fois des libellés individuels et de groupe.
use aspose\slides\ChartType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try
{
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::ClusteredColumn, 20, 20, 500, 300);
$chart->getChartData()->getSeries()->clear();
$chart->getChartData()->getCategories()->clear();
$workbook = $chart->getChartData()->getChartDataWorkbook();
$workbook->clear(0);
$worksheetIndex = 0;
$categoryCell = $workbook->getCell(0, "c2", "A");
$category = $chart->getChartData()->getCategories()->add($categoryCell);
$category->getGroupingLevels()->setGroupingItem(1, "Group1");
$categoryCell = $workbook->getCell(0, "c3", "B");
$category = $chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, "c4", "C");
$category = $chart->getChartData()->getCategories()->add($categoryCell);
$category->getGroupingLevels()->setGroupingItem(1, "Group2");
$categoryCell = $workbook->getCell(0, "c5", "D");
$category = $chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, "c6", "E");
$category = $chart->getChartData()->getCategories()->add($categoryCell);
$category->getGroupingLevels()->setGroupingItem(1, "Group3");
$categoryCell = $workbook->getCell(0, "c7", "F");
$category = $chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell(0, "c8", "G");
$category = $chart->getChartData()->getCategories()->add($categoryCell);
$category->getGroupingLevels()->setGroupingItem(1, "Group4");
$categoryCell = $workbook->getCell(0, "c9", "H");
$category = $chart->getChartData()->getCategories()->add($categoryCell);
$seriesNameCell = $workbook->getCell(0, "D1", "Series 1");
$series = $chart->getChartData()->getSeries()->add($seriesNameCell, ChartType::ClusteredColumn);
$valueCell = $workbook->getCell($worksheetIndex, "D2", 10);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, "D3", 20);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, "D4", 30);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, "D5", 40);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, "D6", 50);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, "D7", 60);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, "D8", 70);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, "D9", 80);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$presentation->save("AsposeChart.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
Le résultat :

Supprimer un libellé de trimestre
Téléchargez quarters.pptx et placez‑le dans le même répertoire que le script PHP. Son graphique montre neuf mois et une seule série de ventes avec des valeurs de 10 à 18. Sur l’axe de catégorie, Q1 couvre janvier à mars, Q2 couvre avril à juin, et Q3 couvre juillet à septembre.
Avril est la quatrième catégorie (index 3) et porte le libellé Q2. Utilisez getGroupingLevels pour accéder aux niveaux de groupement d’avril, puis appelez deleteGroupingItem avec le niveau 1 pour supprimer son libellé de trimestre. Le niveau 0 représente le mois lui‑-même et ne peut pas être supprimé avec cette méthode.
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation(__DIR__ . "/quarters.pptx");
try
{
$chart = $presentation->getSlides()->get_Item(0)->getShapes()->get_Item(0);
$april = $chart->getChartData()->getCategories()->get_Item(3);
$april->getGroupingLevels()->deleteGroupingItem(1);
$presentation->save(__DIR__ . "/quarters-updated.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
$reopened = new Presentation(__DIR__ . "/quarters-updated.pptx");
try
{
$updatedChart = $reopened->getSlides()->get_Item(0)->getShapes()->get_Item(0);
$data = $updatedChart->getChartData();
$months = [];
$categories = $data->getCategories();
for ($i = 0; $i < java_values($categories->size()); $i++)
{
$months[] = (string)$categories->get_Item($i)->getAsCell()->getValue();
}
$sales = [];
$points = $data->getSeries()->get_Item(0)->getDataPoints();
for ($i = 0; $i < java_values($points->size()); $i++)
{
$sales[] = (string)$points->get_Item($i)->getValue()->getData();
}
echo implode(", ", $months), PHP_EOL;
echo implode(", ", $sales), PHP_EOL;
}
finally
{
$reopened->dispose();
}
Après avoir rouvert le graphique, l’exemple affiche les mois originaux (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep) et les valeurs de ventes (10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0) dans le même ordre. Ouvrez quarters-updated.pptx dans PowerPoint pour comparer les libellés d’axe. Le libellé Q2 et la frontière de groupe avant avril disparaissent, de sorte que Q1 couvre janvier à juin. Q3 commence toujours en juillet.

Créer des graphiques cartographiques
Les graphiques cartographiques servent à visualiser des données géographiques en associant l’information à des emplacements spécifiques tels que pays, états ou villes. Ils sont particulièrement utiles pour analyser des tendances régionales, des données démographiques et des répartitions spatiales de manière claire et visuellement attrayante.
Cet exemple utilise addChart pour créer un graphique cartographique avec les données géographiques par défaut et l’enregistre pour visualisation dans PowerPoint.
use aspose\slides\ChartType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try
{
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::Map, 20, 20, 500, 300);
$presentation->save("mapChart.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
Le résultat :

Note
L’image ci‑dessus montre la présentation enregistrée ouverte dans PowerPoint. Aspose.Slides écrit correctement le graphique cartographique et ses données, mais il ne dessine pas les graphiques cartographiques lui‑même : lorsqu’une diapositive contenant un tel graphique est rendue en image ou convertie en PDF ou SVG, la zone du graphique apparaît vide. Les autres formes sur la même diapositive ne sont pas affectées.Créer des graphiques combinés
Un graphique combiné (ou combo) combine deux types de graphiques ou plus dans un même diagramme. Ce graphique vous permet de mettre en évidence, comparer ou examiner les différences entre deux ensembles de données ou plus, aidant à identifier les relations entre eux.

Cet exemple combine deux séries de colonnes groupées avec une série linéaire sur quatre catégories. Les colonnes utilisent l’axe vertical principal, tandis que setPlotOnSecondAxis place la ligne sur un axe vertical secondaire à droite. Les fonctions d’assistance configurent le titre, la légende, les libellés d’axe et les quadrillages.
use aspose\slides\AxisPositionType;
use aspose\slides\ChartType;
use aspose\slides\CrossesType;
use aspose\slides\FillType;
use aspose\slides\LegendPositionType;
use aspose\slides\NullableBool;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
function createComboChart()
{
$presentation = new Presentation();
try
{
$chart = createChartWithFirstSeries($presentation->getSlides()->get_Item(0));
addSecondSeriesToChart($chart);
addThirdSeriesToChart($chart);
setPrimaryAxesFormat($chart);
setSecondaryAxesFormat($chart);
$presentation->save("combo-chart.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
}
function createChartWithFirstSeries($slide)
{
$chart = $slide->getShapes()->addChart(ChartType::ClusteredColumn, 50, 50, 600, 400);
$chart->setTitle(true);
$chart->getChartTitle()->addTextFrameForOverriding("Chart Title");
$chart->getChartTitle()->setOverlay(false);
$portionFormat = $chart->getChartTitle()->getTextFrameForOverriding()->getParagraphs()->get_Item(0)->getParagraphFormat()->getDefaultPortionFormat();
$portionFormat->setFontBold(NullableBool::False);
$portionFormat->setFontHeight(18);
$chart->getLegend()->setPosition(LegendPositionType::Bottom);
$chart->getLegend()->getTextFormat()->getPortionFormat()->setFontHeight(12);
$chart->getChartData()->getSeries()->clear();
$chart->getChartData()->getCategories()->clear();
$workbook = $chart->getChartData()->getChartDataWorkbook();
$worksheetIndex = 0;
$categoryCell = $workbook->getCell($worksheetIndex, 1, 0, "Category 1");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell($worksheetIndex, 2, 0, "Category 2");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell($worksheetIndex, 3, 0, "Category 3");
$chart->getChartData()->getCategories()->add($categoryCell);
$categoryCell = $workbook->getCell($worksheetIndex, 4, 0, "Category 4");
$chart->getChartData()->getCategories()->add($categoryCell);
$seriesNameCell = $workbook->getCell($worksheetIndex, 0, 1, "Series 1");
$series = $chart->getChartData()->getSeries()->add($seriesNameCell, $chart->getType());
$series->getParentSeriesGroup()->setOverlap(-25);
$series->getParentSeriesGroup()->setGapWidth(220);
$valueCell = $workbook->getCell($worksheetIndex, 1, 1, 4.3);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, 2, 1, 2.5);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, 3, 1, 3.5);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, 4, 1, 4.5);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
return $chart;
}
function addSecondSeriesToChart($chart)
{
$workbook = $chart->getChartData()->getChartDataWorkbook();
$worksheetIndex = 0;
$seriesNameCell = $workbook->getCell($worksheetIndex, 0, 2, "Series 2");
$series = $chart->getChartData()->getSeries()->add($seriesNameCell, ChartType::ClusteredColumn);
$series->getParentSeriesGroup()->setOverlap(-25);
$series->getParentSeriesGroup()->setGapWidth(220);
$valueCell = $workbook->getCell($worksheetIndex, 1, 2, 2.4);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, 2, 2, 4.4);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, 3, 2, 1.8);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, 4, 2, 2.8);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
}
function addThirdSeriesToChart($chart)
{
$workbook = $chart->getChartData()->getChartDataWorkbook();
$worksheetIndex = 0;
$seriesNameCell = $workbook->getCell($worksheetIndex, 0, 3, "Series 3");
$series = $chart->getChartData()->getSeries()->add($seriesNameCell, ChartType::Line);
$valueCell = $workbook->getCell($worksheetIndex, 1, 3, 2.0);
$series->getDataPoints()->addDataPointForLineSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, 2, 3, 2.0);
$series->getDataPoints()->addDataPointForLineSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, 3, 3, 3.0);
$series->getDataPoints()->addDataPointForLineSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, 4, 3, 5.0);
$series->getDataPoints()->addDataPointForLineSeries($valueCell);
$series->setPlotOnSecondAxis(true);
}
function setPrimaryAxesFormat($chart)
{
$horizontalAxis = $chart->getAxes()->getHorizontalAxis();
$horizontalAxis->getTextFormat()->getPortionFormat()->setFontHeight(12);
$horizontalAxis->getFormat()->getLine()->getFillFormat()->setFillType(FillType::NoFill);
setAxisTitle($horizontalAxis, "X Axis");
$verticalAxis = $chart->getAxes()->getVerticalAxis();
$verticalAxis->getTextFormat()->getPortionFormat()->setFontHeight(12);
$verticalAxis->getFormat()->getLine()->getFillFormat()->setFillType(FillType::NoFill);
setAxisTitle($verticalAxis, "Y Axis 1");
$majorGridLinesFormat = $verticalAxis->getMajorGridLinesFormat()->getLine()->getFillFormat();
$majorGridLinesFormat->setFillType(FillType::Solid);
$color = new Java("java.awt.Color", 217, 217, 217);
$majorGridLinesFormat->getSolidFillColor()->setColor($color);
}
function setSecondaryAxesFormat($chart)
{
$secondaryHorizontalAxis = $chart->getAxes()->getSecondaryHorizontalAxis();
$secondaryHorizontalAxis->setPosition(AxisPositionType::Bottom);
$secondaryHorizontalAxis->setCrossType(CrossesType::Maximum);
$secondaryHorizontalAxis->setVisible(false);
$secondaryHorizontalAxis->getMajorGridLinesFormat()->getLine()->getFillFormat()->setFillType(FillType::NoFill);
$secondaryHorizontalAxis->getMinorGridLinesFormat()->getLine()->getFillFormat()->setFillType(FillType::NoFill);
$secondaryVerticalAxis = $chart->getAxes()->getSecondaryVerticalAxis();
$secondaryVerticalAxis->setPosition(AxisPositionType::Right);
$secondaryVerticalAxis->getTextFormat()->getPortionFormat()->setFontHeight(12);
$secondaryVerticalAxis->getFormat()->getLine()->getFillFormat()->setFillType(FillType::NoFill);
$secondaryVerticalAxis->getMajorGridLinesFormat()->getLine()->getFillFormat()->setFillType(FillType::NoFill);
$secondaryVerticalAxis->getMinorGridLinesFormat()->getLine()->getFillFormat()->setFillType(FillType::NoFill);
setAxisTitle($secondaryVerticalAxis, "Y Axis 2");
}
function setAxisTitle($axis, $axisTitle)
{
$axis->setTitle(true);
$axis->getTitle()->setOverlay(false);
$titlePortionFormat = $axis->getTitle()->addTextFrameForOverriding($axisTitle)->getParagraphs()->get_Item(0)->getParagraphFormat()->getDefaultPortionFormat();
$titlePortionFormat->setFontBold(NullableBool::False);
$titlePortionFormat->setFontHeight(12);
}
createComboChart();
Mettre à jour les graphiques
Aspose.Slides pour PHP via Java vous permet de mettre à jour les graphiques PowerPoint en modifiant les données du graphique, le formatage et le style. Cette fonctionnalité simplifie le processus de maintien des présentations à jour avec du contenu dynamique et garantit que les graphiques reflètent précisément les données et les normes visuelles actuelles.
Cet exemple met à jour le graphique nommé “My chart” sur la première diapositive d’une présentation existante. Il nécessite deux séries de colonnes avec trois points de données chacune, les libellés de catégorie étant dans la colonne A et les noms de séries dans la première ligne de la première feuille de calcul. L’exemple utilise getCell pour modifier les cellules du classeur, met à jour les valeurs des séries, ajoute une troisième série et change le type du graphique en cylindres groupés via setType.
use aspose\slides\ChartType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$chartName = "My chart";
$chartClass = new JavaClass("com.aspose.slides.IChart");
$presentation = new Presentation("ExistingChart.pptx");
try
{
$slide = $presentation->getSlides()->get_Item(0);
for ($i = 0; $i < java_values($slide->getShapes()->size()); $i++)
{
$shape = $slide->getShapes()->get_Item($i);
if (java_instanceof($shape, $chartClass) && $chartName === java_values($shape->getName()))
{
$chart = $shape;
$worksheetIndex = 0;
$workbook = $chart->getChartData()->getChartDataWorkbook();
$workbook->getCell($worksheetIndex, 1, 0, "Modified Category 1");
$workbook->getCell($worksheetIndex, 2, 0, "Modified Category 2");
$series = $chart->getChartData()->getSeries()->get_Item(0);
$workbook->getCell($worksheetIndex, 0, 1, "New_Series 1");
$series->getDataPoints()->get_Item(0)->getValue()->setData(90);
$series->getDataPoints()->get_Item(1)->getValue()->setData(123);
$series->getDataPoints()->get_Item(2)->getValue()->setData(44);
$series = $chart->getChartData()->getSeries()->get_Item(1);
$workbook->getCell($worksheetIndex, 0, 2, "New_Series 2");
$series->getDataPoints()->get_Item(0)->getValue()->setData(23);
$series->getDataPoints()->get_Item(1)->getValue()->setData(67);
$series->getDataPoints()->get_Item(2)->getValue()->setData(99);
$seriesNameCell = $workbook->getCell($worksheetIndex, 0, 3, "Series 3");
$series = $chart->getChartData()->getSeries()->add($seriesNameCell, $chart->getType());
$valueCell = $workbook->getCell($worksheetIndex, 1, 3, 20);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, 2, 3, 50);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$valueCell = $workbook->getCell($worksheetIndex, 3, 3, 30);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
$chart->setType(ChartType::ClusteredCylinder);
}
}
$presentation->save("AsposeChartModified.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
Définir la plage de données d’un graphique
Pour inspecter la plage déjà utilisée par un graphique existant, voir Retrieve a Chart’s Data Range.
Aspose.Slides pour PHP via Java offre la flexibilité de définir une plage de données spécifique d’une feuille de calcul comme source des données de votre graphique. Cela signifie que vous pouvez mapper directement une portion de votre feuille de calcul au graphique, vous permettant de contrôler quelles cellules contribuent aux séries et aux catégories du graphique. En conséquence, vous pouvez facilement mettre à jour et synchroniser vos graphiques avec les dernières modifications de données dans votre feuille, garantissant que vos présentations PowerPoint reflètent des informations actuelles et précises.
Cet exemple utilise setRange pour définir la source de données du graphique nommé “My chart” sur la première diapositive d’une présentation existante sur Sheet1!A1:B4. Le classeur du graphique doit contenir cette feuille de calcul et une plage remplie avec un titre de série dans la première ligne, des libellés de catégorie dans la colonne A et trois valeurs dans la colonne B.
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$chartName = "My chart";
$chartClass = new JavaClass("com.aspose.slides.IChart");
$presentation = new Presentation("ExistingChart.pptx");
try
{
$slide = $presentation->getSlides()->get_Item(0);
for ($i = 0; $i < java_values($slide->getShapes()->size()); $i++)
{
$shape = $slide->getShapes()->get_Item($i);
if (java_instanceof($shape, $chartClass) && $chartName === java_values($shape->getName()))
{
$chart = $shape;
$chart->getChartData()->setRange("Sheet1!A1:B4");
}
}
$presentation->save("SetDataRange.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
Utiliser des marqueurs par défaut dans les graphiques
Lorsque vous utilisez des marqueurs par défaut dans les graphiques, chaque série de graphique obtient automatiquement un symbole de marqueur différent.
Cet exemple utilise addChart pour créer un graphique avec deux séries linéaires et une légende. Les paramètres du marqueur accessibles via getMarker conservent les symboles de marqueur assignés automatiquement. La première série comprend une valeur négative et une valeur manquante, représentée par null, tandis que la seconde possède une valeur pour chaque catégorie.
use aspose\slides\ChartType;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try
{
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::LineWithMarkers, 10, 10, 400, 400);
$chart->getChartData()->getSeries()->clear();
$chart->getChartData()->getCategories()->clear();
$workbook = $chart->getChartData()->getChartDataWorkbook();
$seriesNameCell = $workbook->getCell(0, 0, 1, "Series 1");
$series = $chart->getChartData()->getSeries()->add($seriesNameCell, $chart->getType());
$categoryCell = $workbook->getCell(0, 1, 0, "C1");
$chart->getChartData()->getCategories()->add($categoryCell);
$valueCell = $workbook->getCell(0, 1, 1, 24);
$series->getDataPoints()->addDataPointForLineSeries($valueCell);
$categoryCell = $workbook->getCell(0, 2, 0, "C2");
$chart->getChartData()->getCategories()->add($categoryCell);
$valueCell = $workbook->getCell(0, 2, 1, 23);
$series->getDataPoints()->addDataPointForLineSeries($valueCell);
$categoryCell = $workbook->getCell(0, 3, 0, "C3");
$chart->getChartData()->getCategories()->add($categoryCell);
$valueCell = $workbook->getCell(0, 3, 1, -10);
$series->getDataPoints()->addDataPointForLineSeries($valueCell);
$categoryCell = $workbook->getCell(0, 4, 0, "C4");
$chart->getChartData()->getCategories()->add($categoryCell);
$valueCell = $workbook->getCell(0, 4, 1, null);
$series->getDataPoints()->addDataPointForLineSeries($valueCell);
$seriesNameCell = $workbook->getCell(0, 0, 2, "Series 2");
$secondSeries = $chart->getChartData()->getSeries()->add($seriesNameCell, $chart->getType());
$valueCell = $workbook->getCell(0, 1, 2, 30);
$secondSeries->getDataPoints()->addDataPointForLineSeries($valueCell);
$valueCell = $workbook->getCell(0, 2, 2, 10);
$secondSeries->getDataPoints()->addDataPointForLineSeries($valueCell);
$valueCell = $workbook->getCell(0, 3, 2, 60);
$secondSeries->getDataPoints()->addDataPointForLineSeries($valueCell);
$valueCell = $workbook->getCell(0, 4, 2, 40);
$secondSeries->getDataPoints()->addDataPointForLineSeries($valueCell);
$chart->setLegend(true);
$chart->getLegend()->setOverlay(false);
$presentation->save("DefaultMarkersInChart.pptx", SaveFormat::Pptx);
}
finally
{
$presentation->dispose();
}
FAQ
Quels types de graphiques sont pris en charge par Aspose.Slides pour PHP via Java ?
Aspose.Slides pour PHP via Java prend en charge un large éventail de types de graphiques, y compris les graphiques à barres, lignes, circulaires, aires, nuage de points, histogrammes, radar et bien d’autres. Cette flexibilité vous permet de choisir le type de graphique le plus approprié à vos besoins de visualisation de données.
Comment ajouter un nouveau graphique à une diapositive ?
Pour ajouter un graphique, créez d’abord une instance de la classe Presentation, récupérez la diapositive désirée à l’aide de son index, puis appelez la méthode pour ajouter un graphique, en spécifiant le type de graphique et les données initiales. Ce processus intègre le graphique directement dans votre présentation.
Comment mettre à jour les données affichées dans un graphique ?
Vous pouvez mettre à jour les données d’un graphique en accédant à son classeur de données (ChartDataWorkbook), en supprimant les séries et catégories par défaut, puis en ajoutant vos données personnalisées. Cela vous permet de rafraîchir programmatiquement le graphique pour refléter les dernières données.
Est‑il possible de personnaliser l’apparence du graphique ?
Oui, Aspose.Slides pour PHP via Java offre de vastes options de personnalisation. Vous pouvez modifier les couleurs, les polices, les libellés, les légendes et d’autres éléments de formatage pour adapter l’apparence du graphique à vos exigences de conception spécifiques.