PHP를 사용하여 프레젠테이션에서 차트 데이터 레이블 관리
소개
데이터 레이블은 차트 시리즈와 개별 데이터 포인트에 대한 정보를 표시하여 독자가 값을 식별하고 차트를 이해하는 데 도움을 줍니다. 이 문서에서는 값 서식 지정, 백분율 표시, 레이블 텍스트 읽기, 축 최대값을 초과한 레이블 제어, 범주 축 레이블 간격 조정 및 파이 차트 레이블 위치 지정 방법을 설명합니다.
보이는 데이터 레이블 수
Use getCountOfVisibleDataLabels to check how many data labels are enabled for display before publishing a presentation. Unlike getCount, which returns the total number of labels in the collection, it takes the series defaults and individual label settings into account.
This example creates a column chart with one series and three data points. It accesses the series' label collection through getLabels and prints the visible count as the settings change: 0, 3, 2, 3. The total count remains 3.
use aspose\slides\Presentation;
use aspose\slides\ChartType;
$presentation = new Presentation();
try {
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::ClusteredColumn, 50, 50, 500, 300);
$chart->getChartData()->getSeries()->clear();
$chart->getChartData()->getCategories()->clear();
$workbook = $chart->getChartData()->getChartDataWorkbook();
$seriesCell = $workbook->getCell(0, 0, 1, "Values");
$series = $chart->getChartData()->getSeries()->add($seriesCell, $chart->getType());
for ($i = 0; $i < 3; $i++) {
$categoryCell = $workbook->getCell(0, $i + 1, 0, "Category " . ($i + 1));
$chart->getChartData()->getCategories()->add($categoryCell);
$valueCell = $workbook->getCell(0, $i + 1, 1, ($i + 1) * 10);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
}
$labels = $series->getLabels();
echo "Total: " . java_values($labels->getCount()) . "; visible: " . java_values($labels->getCountOfVisibleDataLabels()) . PHP_EOL; // 전체: 3; 표시: 0
$labels->getDefaultDataLabelFormat()->setShowValue(true);
echo "Visible: " . java_values($labels->getCountOfVisibleDataLabels()) . PHP_EOL; // 표시: 3
$labels->get_Item(1)->getDataLabelFormat()->setShowValue(false);
echo "Visible: " . java_values($labels->getCountOfVisibleDataLabels()) . PHP_EOL; // 표시: 2
$labels->get_Item(1)->getDataLabelFormat()->setShowLegendKey(true);
echo "Visible: " . java_values($labels->getCountOfVisibleDataLabels()) . PHP_EOL; // 표시: 3
} finally {
$presentation->dispose();
}
The series' getDefaultDataLabelFormat supplies the default settings. Passing true to setShowValue there displays values for all three labels. Passing false through one label’s getDataLabelFormat overrides that setting for the selected label. Passing true to setShowLegendKey makes that label count as visible again, even though its value remains hidden.
The visible count reflects visibility settings. It does not measure whether labels overlap, are clipped, or are readable in the rendered chart.
차트 데이터 레이블에서 데이터 정밀도 설정
Use setNumberFormatOfValues to format series values. This example creates a line chart with default data, displays its data table, and enables value labels for the first series. The format #,##0.00 displays a thousands separator and two decimal places without changing the underlying values.
use aspose\slides\Presentation;
use aspose\slides\ChartType;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try {
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::Line, 50, 50, 450, 300);
$chart->setDataTable(true);
$series = $chart->getChartData()->getSeries()->get_Item(0);
$series->setNumberFormatOfValues("#,##0.00");
$series->getLabels()->getDefaultDataLabelFormat()->setShowValue(true);
$presentation->save("PrecisionOfDatalabels_out.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
To format the numeric cells in a chart’s embedded workbook, see 워크북 셀에 대한 사용자 지정 숫자 형식 설정. That example also shows value labels following their source cell formats while preserving the stored numeric values.
백분율을 레이블로 표시
For a stacked column chart, calculate each value as a percentage of its category total and assign the text to the text frame returned by getTextFrameForOverriding. This example uses the default chart data and displays percentages with two decimal places in an 8-point font. Categories with a total of zero are skipped to avoid division by zero. Recalculate the custom label text if the chart data changes.
use aspose\slides\Presentation;
use aspose\slides\ChartType;
use aspose\slides\Portion;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try {
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::StackedColumn, 20, 20, 400, 400);
$categoryCount = java_values($chart->getChartData()->getCategories()->size());
$categoryTotals = array_fill(0, $categoryCount, 0.0);
for ($k = 0; $k < $categoryCount; $k++) {
for ($i = 0; $i < java_values($chart->getChartData()->getSeries()->size()); $i++) {
$series = $chart->getChartData()->getSeries()->get_Item($i);
$pointValue = java_values($series->getDataPoints()->get_Item($k)->getValue()->getData());
$categoryTotals[$k] += $pointValue;
}
}
for ($x = 0; $x < java_values($chart->getChartData()->getSeries()->size()); $x++) {
$series = $chart->getChartData()->getSeries()->get_Item($x);
$series->getLabels()->getDefaultDataLabelFormat()->setShowLegendKey(false);
for ($j = 0; $j < java_values($series->getDataPoints()->size()); $j++) {
$label = $series->getDataPoints()->get_Item($j)->getLabel();
if ($categoryTotals[$j] == 0) {
continue;
}
$pointValue = java_values($series->getDataPoints()->get_Item($j)->getValue()->getData());
$dataPointPercent = ($pointValue / $categoryTotals[$j]) * 100;
$portion = new Portion();
$portion->setText(sprintf("%.2F %%", $dataPointPercent));
$portion->getPortionFormat()->setFontHeight(8);
$label->getTextFrameForOverriding()->setText("");
$paragraph = $label->getTextFrameForOverriding()->getParagraphs()->get_Item(0);
$paragraph->getPortions()->add($portion);
$label->getDataLabelFormat()->setShowValue(true);
$label->getDataLabelFormat()->setShowSeriesName(false);
$label->getDataLabelFormat()->setShowPercentage(false);
$label->getDataLabelFormat()->setShowLegendKey(false);
$label->getDataLabelFormat()->setShowCategoryName(false);
$label->getDataLabelFormat()->setShowBubbleSize(false);
}
}
$presentation->save("DisplayPercentageAsLabels_out.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
차트 데이터 레이블에 백분율 기호 설정
When values are stored as fractions, use setNumberFormat to display percentages. Pass false to setNumberFormatLinkedToSource to apply the label format independently of the source cells.
This example creates a 100% stacked column chart with red and blue series across four categories. Each pair of values adds up to 1. The label format 0.0% displays 0.30 as 30.0%, while the vertical axis uses two decimal places. Both series use white, 10-point label text.
use aspose\slides\Presentation;
use aspose\slides\ChartType;
use aspose\slides\FillType;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try {
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::PercentsStackedColumn, 20, 20, 500, 400);
$chart->getAxes()->getVerticalAxis()->setNumberFormatLinkedToSource(false);
$chart->getAxes()->getVerticalAxis()->setNumberFormat("0.00%");
$chart->getChartData()->getSeries()->clear();
$chart->getChartData()->getCategories()->clear();
$workbook = $chart->getChartData()->getChartDataWorkbook();
$worksheetIndex = 0;
for ($i = 0; $i < 4; $i++) {
$categoryCell = $workbook->getCell($worksheetIndex, $i + 1, 0, "Category " . ($i + 1));
$chart->getChartData()->getCategories()->add($categoryCell);
}
$colors = java("java.awt.Color");
$seriesNames = [ "Reds", "Blues" ];
$seriesColors = [ $colors->RED, $colors->BLUE ];
$values = [ [ 0.30, 0.50, 0.80, 0.65 ], [ 0.70, 0.50, 0.20, 0.35 ] ];
for ($i = 0; $i < count($seriesNames); $i++) {
$seriesCell = $workbook->getCell($worksheetIndex, 0, $i + 1, $seriesNames[$i]);
$series = $chart->getChartData()->getSeries()->add($seriesCell, $chart->getType());
for ($j = 0; $j < 4; $j++) {
$valueCell = $workbook->getCell($worksheetIndex, $j + 1, $i + 1, $values[$i][$j]);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
}
$series->getFormat()->getFill()->setFillType(FillType::Solid);
$series->getFormat()->getFill()->getSolidFillColor()->setColor($seriesColors[$i]);
$labelFormat = $series->getLabels()->getDefaultDataLabelFormat();
$labelFormat->setShowValue(true);
$labelFormat->setNumberFormatLinkedToSource(false);
$labelFormat->setNumberFormat("0.0%");
$labelFormat->getTextFormat()->getPortionFormat()->setFontHeight(10);
$labelFormat->getTextFormat()->getPortionFormat()->getFillFormat()->setFillType(FillType::Solid);
$labelFormat->getTextFormat()->getPortionFormat()->getFillFormat()->getSolidFillColor()->setColor($colors->WHITE);
}
$presentation->save("SetDataLabelsPercentageSign_out.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
데이터 레이블의 실제 텍스트 읽기
Use getActualLabelText to retrieve the text produced by a data label’s settings. This is useful when extracting labels for reports, searching presentation content, or validating generated charts. In the example below, the default data label format combines each category name, series name, and value. One point formats its value as a percentage, and another uses custom text from getTextFrameForOverriding.
use aspose\slides\Presentation;
use aspose\slides\ChartType;
$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();
$firstCategoryCell = $workbook->getCell(0, 1, 0, "Q1");
$chart->getChartData()->getCategories()->add($firstCategoryCell);
$secondCategoryCell = $workbook->getCell(0, 2, 0, "Q2");
$chart->getChartData()->getCategories()->add($secondCategoryCell);
$northSeriesCell = $workbook->getCell(0, 0, 1, "North");
$north = $chart->getChartData()->getSeries()->add($northSeriesCell, $chart->getType());
$northFirstValueCell = $workbook->getCell(0, 1, 1, 0.25);
$north->getDataPoints()->addDataPointForBarSeries($northFirstValueCell);
$northSecondValueCell = $workbook->getCell(0, 2, 1, 0.75);
$north->getDataPoints()->addDataPointForBarSeries($northSecondValueCell);
$southSeriesCell = $workbook->getCell(0, 0, 2, "South");
$south = $chart->getChartData()->getSeries()->add($southSeriesCell, $chart->getType());
$southFirstValueCell = $workbook->getCell(0, 1, 2, 0.40);
$south->getDataPoints()->addDataPointForBarSeries($southFirstValueCell);
$southSecondValueCell = $workbook->getCell(0, 2, 2, 0.60);
$south->getDataPoints()->addDataPointForBarSeries($southSecondValueCell);
for ($i = 0; $i < java_values($chart->getChartData()->getSeries()->size()); $i++) {
$series = $chart->getChartData()->getSeries()->get_Item($i);
$format = $series->getLabels()->getDefaultDataLabelFormat();
$format->setShowCategoryName(true);
$format->setShowSeriesName(true);
$format->setShowValue(true);
}
$north->getLabels()->get_Item(1)->getDataLabelFormat()->setNumberFormatLinkedToSource(false);
$north->getLabels()->get_Item(1)->getDataLabelFormat()->setNumberFormat("0%");
$south->getLabels()->get_Item(0)->getTextFrameForOverriding()->setText("Reviewed");
for ($i = 0; $i < java_values($chart->getChartData()->getSeries()->size()); $i++) {
$series = $chart->getChartData()->getSeries()->get_Item($i);
for ($j = 0; $j < java_values($series->getDataPoints()->size()); $j++) {
$point = $series->getDataPoints()->get_Item($j);
$label = $point->getLabel();
if (!java_values($label->isVisible())) {
continue;
}
echo "Value: " . java_values($point->getValue()->getData()) . "; label: " . java_values($label->getActualLabelText()) . PHP_EOL;
}
}
} finally {
$presentation->dispose();
}
The number stored in a data point remains 0.75, even when its label shows 75% along with the category and series names. Custom text replaces the generated label text. getActualLabelText returns the resulting label string in either case. Check isVisible separately, as shown above, when you want to extract only visible labels.
축 최대값을 초과한 데이터 레이블 제어
When you limit an axis range manually, some data points may exceed its maximum. Use setShowDataLabelsOverMaximum to control whether their data labels are shown. This setting changes label visibility; it does not change the axis range or the underlying data values.
The example below creates a 2D clustered column chart with values of 60 and 120. It passes false to setAutomaticMaxValue and sets the maximum to 100 with setMaxValue on the vertical axis. The first slide allows labels beyond the maximum; a copy of that slide disables them. Both slides are saved in DataLabelsOverMaximum.pptx.
Enable value labels with setShowValue. The chart-level setting does not enable value display by itself or override an individual label’s disabled value display. This example enables values for the entire series and uses setPosition to place labels at the outside end of each column.
use aspose\slides\Presentation;
use aspose\slides\ChartType;
use aspose\slides\LegendDataLabelPosition;
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->setLegend(false);
$chart->getChartData()->getSeries()->clear();
$chart->getChartData()->getCategories()->clear();
$workbook = $chart->getChartData()->getChartDataWorkbook();
$firstCategory = $workbook->getCell(0, 1, 0, "Within range");
$secondCategory = $workbook->getCell(0, 2, 0, "Above maximum");
$chart->getChartData()->getCategories()->add($firstCategory);
$chart->getChartData()->getCategories()->add($secondCategory);
$seriesName = $workbook->getCell(0, 0, 1, "Values");
$series = $chart->getChartData()->getSeries()->add($seriesName, $chart->getType());
$firstValue = $workbook->getCell(0, 1, 1, 60);
$secondValue = $workbook->getCell(0, 2, 1, 120);
$series->getDataPoints()->addDataPointForBarSeries($firstValue);
$series->getDataPoints()->addDataPointForBarSeries($secondValue);
$series->getLabels()->getDefaultDataLabelFormat()->setShowValue(true);
$series->getLabels()->getDefaultDataLabelFormat()->setPosition(LegendDataLabelPosition::OutsideEnd);
$chart->getAxes()->getVerticalAxis()->setAutomaticMaxValue(false);
$chart->getAxes()->getVerticalAxis()->setMaxValue(100);
$chart->setShowDataLabelsOverMaximum(true);
$secondSlide = $presentation->getSlides()->addClone($slide);
$secondChart = $secondSlide->getShapes()->get_Item(0);
$secondChart->setShowDataLabelsOverMaximum(false);
$presentation->save("DataLabelsOverMaximum.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
The following images show the saved slides rendered by Microsoft PowerPoint. With true, the label 120 is visible at the upper boundary; with false, it is hidden. The label 60 remains visible, the axis maximum stays at 100, and the second data point remains 120 in both cases.
| setShowDataLabelsOverMaximum(true) | setShowDataLabelsOverMaximum(false) |
|---|---|
![]() |
![]() |
Chart Type
This example uses a 2D column chart with a value axis. Charts without a value axis, such as pie and doughnut charts, do not have an axis maximum to limit in this way.축에서 레이블 거리 설정
Use setLabelOffset to control the distance between category axis labels and the axis. The value is a percentage of the maximum font size of the axis labels. This example creates a clustered column chart and sets the horizontal axis label offset to 500. This setting affects category axis labels rather than labels attached to individual data points.
use aspose\slides\Presentation;
use aspose\slides\ChartType;
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->getAxes()->getHorizontalAxis()->setLabelOffset(500);
$presentation->save("SetCategoryAxisLabelDistance_out.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
레이블 위치 조정
On a pie chart, adjust data label positions to improve spacing and make room for leader lines.
This example displays the value of the first data point, places its label outside the slice, and adjusts its horizontal and vertical offsets using setX and setY. These offsets are relative to the chart width and height, respectively.
use aspose\slides\Presentation;
use aspose\slides\ChartType;
use aspose\slides\LegendDataLabelPosition;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try {
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::Pie, 50, 50, 200, 200);
$series = $chart->getChartData()->getSeries();
$label = $series->get_Item(0)->getLabels()->get_Item(0);
$label->getDataLabelFormat()->setShowValue(true);
$label->getDataLabelFormat()->setPosition(LegendDataLabelPosition::OutsideEnd);
$label->setX(0.71);
$label->setY(0.04);
$presentation->save("presentation.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}

리더 라인 서식 지정
When pie chart labels sit outside their slices, leader lines help readers match each value to the correct slice. A contrasting color and a slightly thicker line can make these connections easier to follow, while transparency and a dashed style keep the lines visually unobtrusive.
Use getLeaderLinesFormat to format leader lines at the series' data label collection level. The settings in $series->getLabels()->getLeaderLinesFormat()->getLine() apply to the collection, rather than to an individual label.
This example creates a pie chart with default data, displays values outside the slices, and enables setShowLeaderLines. It moves two labels farther from their slices using setX and setY offsets, expressed as fractions of the chart width and height. No input presentation is required.
The line’s getFillFormat sets a solid blue color with an alpha value of 191 out of 255, giving approximately 25% transparency. setWidth sets the thickness to 2 points, and setDashStyle makes the line dashed.
use aspose\slides\Presentation;
use aspose\slides\ChartType;
use aspose\slides\LegendDataLabelPosition;
use aspose\slides\FillType;
use aspose\slides\LineDashStyle;
use aspose\slides\SaveFormat;
$presentation = new Presentation();
try {
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::Pie, 80, 50, 560, 400);
$chart->setLegend(false);
$series = $chart->getChartData()->getSeries()->get_Item(0);
$labelFormat = $series->getLabels()->getDefaultDataLabelFormat();
$labelFormat->setShowValue(true);
$labelFormat->setPosition(LegendDataLabelPosition::OutsideEnd);
$labelFormat->setShowLeaderLines(true);
// 두 레이블을 슬라이스에서 더 멀리 이동합니다.
$series->getLabels()->get_Item(0)->setX(0.10);
$series->getLabels()->get_Item(0)->setY(-0.05);
$series->getLabels()->get_Item(1)->setX(-0.10);
$series->getLabels()->get_Item(1)->setY(0.05);
$line = $series->getLabels()->getLeaderLinesFormat()->getLine();
$line->getFillFormat()->setFillType(FillType::Solid);
$lineColor = new Java("java.awt.Color", 30, 90, 160, 191);
$line->getFillFormat()->getSolidFillColor()->setColor($lineColor);
$line->setWidth(2);
$line->setDashStyle(LineDashStyle::Dash);
$presentation->save("FormattedLeaderLines.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
Enabling leader lines does not guarantee that a line will appear for every label. Visibility depends on label placement and the chart’s layout behavior. In this example, the two displaced labels have visible leader lines; the labels that remain close to their slices do not need them.
The following image shows the saved FormattedLeaderLines.pptx rendered with Aspose.Slides:

열 차트 위에 여러 행의 데이터 레이블 추가
This example creates a column chart with two rows of data labels above the plot area. Series A displays the visible columns, while Series B and Series C provide the additional labels. Their columns are hidden by removing the fill and outline. The ChartSeriesGroup::setOverlap method aligns all three series with the same category centers.
The ChartPlotArea settings reserve space for the label rows. After Chart::validateChartLayout calculates the default positions, DataLabel::setX and DataLabel::setY preserve the horizontal alignment and apply vertical offsets to arrange the labels in two rows. The numbers remain data labels linked to the series values; only the row headings are separate text shapes.
use aspose\slides\Presentation;
use aspose\slides\ChartType;
use aspose\slides\FillType;
use aspose\slides\LegendDataLabelPosition;
use aspose\slides\LayoutTargetType;
use aspose\slides\ShapeType;
use aspose\slides\SaveFormat;
$colors = java("java.awt.Color");
$presentation = new Presentation();
try {
$slide = $presentation->getSlides()->get_Item(0);
$chart = $slide->getShapes()->addChart(ChartType::ClusteredColumn, 40, 40, 640, 200);
$chart->setTitle(false);
$chart->setLegend(false);
$chart->getTextFormat()->getPortionFormat()->setFontHeight(12);
$chart->getChartData()->getSeries()->clear();
$chart->getChartData()->getCategories()->clear();
$workbook = $chart->getChartData()->getChartDataWorkbook();
$workbook->clear(0);
$categories = [ "North", "South", "East", "West" ];
$seriesNames = [ "Series A", "Series B", "Series C" ];
$seriesValues = [
[ 35, 42, 28, 47 ],
[ 22, 31, 19, 26 ],
[ 12, 16, 14, 18 ]
];
for ($categoryIndex = 0; $categoryIndex < count($categories); $categoryIndex++) {
$categoryCell = $workbook->getCell(0, $categoryIndex + 1, 0, $categories[$categoryIndex]);
$chart->getChartData()->getCategories()->add($categoryCell);
}
for ($seriesIndex = 0; $seriesIndex < count($seriesNames); $seriesIndex++) {
$seriesCell = $workbook->getCell(0, 0, $seriesIndex + 1, $seriesNames[$seriesIndex]);
$series = $chart->getChartData()->getSeries()->add($seriesCell, ChartType::ClusteredColumn);
for ($categoryIndex = 0; $categoryIndex < count($categories); $categoryIndex++) {
$valueCell = $workbook->getCell(0, $categoryIndex + 1, $seriesIndex + 1, $seriesValues[$seriesIndex][$categoryIndex]);
$series->getDataPoints()->addDataPointForBarSeries($valueCell);
}
if ($seriesIndex > 0) {
// B와 C의 열을 숨기지만 데이터 레이블은 유지합니다.
$series->getFormat()->getFill()->setFillType(FillType::NoFill);
$series->getFormat()->getLine()->getFillFormat()->setFillType(FillType::NoFill);
$labelFormat = $series->getLabels()->getDefaultDataLabelFormat();
$labelFormat->setShowValue(true);
$labelFormat->getTextFormat()->getPortionFormat()->setFontHeight(12);
$labelFill = $labelFormat->getTextFormat()->getPortionFormat()->getFillFormat();
$labelFill->setFillType(FillType::Solid);
$labelFill->getSolidFillColor()->setColor($colors->BLACK);
$labelFormat->setPosition(LegendDataLabelPosition::InsideBase);
}
}
// 세 시리즈를 동일한 범주 중심에 맞춥니다.
$chart->getChartData()->getSeries()->get_Item(0)->getParentSeriesGroup()->setOverlap(100);
// 이 간결한 예제에서는 그리드 라인을 적게 사용합니다.
$chart->getAxes()->getVerticalAxis()->setAutomaticMajorUnit(false);
$chart->getAxes()->getVerticalAxis()->setMajorUnit(10);
// 플롯 위에 두 행의 데이터 레이블을 위한 공간을 예약합니다.
$chart->getPlotArea()->setLayoutTargetType(LayoutTargetType::Inner);
$chart->getPlotArea()->setX(0.15);
$chart->getPlotArea()->setY(0.32);
$chart->getPlotArea()->setWidth(0.80);
$chart->getPlotArea()->setHeight(0.48);
$chart->validateChartLayout();
$chartX = java_values($chart->getX());
$chartY = java_values($chart->getY());
$chartHeight = java_values($chart->getHeight());
for ($seriesIndex = 1; $seriesIndex < count($seriesNames); $seriesIndex++) {
$series = $chart->getChartData()->getSeries()->get_Item($seriesIndex);
$rowTop = $seriesIndex == 1 ? 0.15 : 0.03;
for ($categoryIndex = 0; $categoryIndex < count($categories); $categoryIndex++) {
$dataLabel = $series->getDataPoints()->get_Item($categoryIndex)->getLabel();
// 기본 수평 위치를 유지합니다. Y는 다음으로부터의 오프셋입니다.
// 기본 레이블 위치이며, 차트 높이 비율로 표현됩니다.
$actualY = java_values($dataLabel->getActualY());
$dataLabel->setX(0);
$dataLabel->setY($rowTop - $actualY / $chartHeight);
}
// 행 제목만 별도의 텍스트 도형입니다.
$rowHeading = $slide->getShapes()->addAutoShape(ShapeType::Rectangle, $chartX, $chartY + $rowTop * $chartHeight, 85, 18);
$rowHeading->getFillFormat()->setFillType(FillType::NoFill);
$rowHeading->getLineFormat()->getFillFormat()->setFillType(FillType::NoFill);
$rowHeading->addTextFrame($seriesNames[$seriesIndex]);
$rowHeading->getTextFrame()->getTextFrameFormat()->setMarginTop(0);
$rowHeading->getTextFrame()->getTextFrameFormat()->setMarginBottom(0);
$headingFormat = $rowHeading->getTextFrame()->getParagraphs()->get_Item(0)->getPortions()->get_Item(0)->getPortionFormat();
$headingFormat->setFontHeight(12);
$headingFormat->getFillFormat()->setFillType(FillType::Solid);
$headingFormat->getFillFormat()->getSolidFillColor()->setColor($colors->BLACK);
}
$presentation->save("multiple-rows-of-labels.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}

FAQ
밀집된 차트에서 데이터 레이블이 겹치는 것을 어떻게 방지할 수 있나요?
자동 레이블 배치, 리더 라인, 글꼴 크기 축소를 결합하고 필요 시 일부 필드(예: 카테고리)를 숨기거나 극값이나 핵심 포인트에만 레이블을 표시합니다.
값이 0, 음수 또는 비어 있는 경우에만 레이블을 비활성화하려면 어떻게 해야 하나요?
레이블을 활성화하기 전에 데이터를 필터링하고 0, 음수 또는 누락된 값에 대해 표시를 끄는 규칙을 적용합니다.
PDF/이미지로 내보낼 때 일관된 레이블 스타일을 보장하려면 어떻게 해야 하나요?
글꼴 패밀리와 크기를 명시적으로 설정하고 렌더링 환경에 해당 글꼴이 존재하는지 확인하여 대체 글꼴 적용을 방지합니다.

