Customize Chart Data Tables in Presentations Using PHP
Overview
Aspose.Slides for PHP via Java lets you display a chart’s data table and customize its text formatting, borders, and legend keys. This article explains how to enable the table, format its text, control each type of border, and show or hide legend keys. The examples save the configured charts in PPTX files.
Set Font Properties
To display a chart’s data table, pass true to setDataTable. Use getChartDataTable to access the table and configure its text formatting.
- Load the presentation using the Presentation class.
- Add a clustered column chart to the first slide.
- Enable the chart’s data table.
- Enable bold text with setFontBold and pass
20to setFontHeight for 20-point text. - Save the modified presentation.
The following example requires test.pptx in the working directory with at least one slide. It adds a chart with default data at position (50, 50), with a width of 600 points and a height of 400 points. The saved output.pptx contains the chart with its data table enabled and the specified font settings applied.
use aspose\slides\ChartType;
use aspose\slides\NullableBool;
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::ClusteredColumn, 50, 50, 600, 400);
$chart->setDataTable(true);
$portionFormat = $chart->getChartDataTable()->getTextFormat()->getPortionFormat();
$portionFormat->setFontBold(NullableBool::True);
$portionFormat->setFontHeight(20);
$presentation->save("output.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
Customize Data Table Borders
Enable the table with Chart::setDataTable and access it through Chart::getChartDataTable. You can control three types of borders independently:
- setBorderHorizontal controls horizontal cell borders.
- setBorderVertical controls vertical cell borders.
- setBorderOutline controls the outer border of the table.
Pass true to each method to display its borders or false to hide them. The following example creates a clustered column chart with default data, displays horizontal borders and the outer border, and hides vertical borders. It requires no input file. The chart’s position and size are specified in points.
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, 50, 50, 600, 400);
$chart->setDataTable(true);
$dataTable = $chart->getChartDataTable();
$dataTable->setBorderHorizontal(true);
$dataTable->setBorderVertical(false);
$dataTable->setBorderOutline(true);
$presentation->save("data-table-borders.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
The comparison below uses the same chart data and legend key setting in all four cases. Starting with all borders enabled, each remaining variant disables just one border setting. The lower-left variant matches the border settings in the example.

Show or Hide Legend Keys
Legend keys are small colored markers beside the series names in the data table. They help readers match each table row to a chart series. Pass true to setShowLegendKey to show these markers or false to hide them.
The chart’s separate legend is controlled by Chart::setLegend. These settings are independent: hiding the separate legend does not hide the keys inside the data table, and hiding the table’s keys does not hide the separate legend.
The following example creates a chart with default data, enables its data table, and shows legend keys inside it while hiding the separate legend. All table borders are explicitly enabled. No input presentation is required. To hide only the table’s keys, pass false to setShowLegendKey.
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, 50, 50, 600, 400);
$chart->setDataTable(true);
$chart->setLegend(false);
$dataTable = $chart->getChartDataTable();
$dataTable->setBorderHorizontal(true);
$dataTable->setBorderVertical(true);
$dataTable->setBorderOutline(true);
$dataTable->setShowLegendKey(true);
$presentation->save("data-table-legend-keys.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
The comparison below shows the same table with legend keys enabled and disabled. All borders remain enabled, and the separate chart legend is hidden in both cases.

FAQ
Can I show legend keys in a chart’s data table?
Yes. Pass true to setShowLegendKey to display legend keys or false to hide them.
Will the data table be preserved when exporting the presentation to PDF, HTML, or images?
Yes. Aspose.Slides renders the chart and its displayed data table as part of the slide when exporting to PDF, HTML, or images.
Can I work with data tables in charts loaded from a template?
Yes. For a chart loaded from an existing presentation or template, use hasDataTable and setDataTable to check or change whether its data table is displayed.
How can I find charts that have a data table enabled?
Iterate through the shapes on each slide, identify the charts, and call their hasDataTable method. A value of true indicates that the data table is enabled.