PhpSpreadsheetのChartにdatatableを表示する
PhpSpreadsheet\Writer\Xlsx\Chart.php
Write Chart Plot Area.に下記を追加する。
if (($chartType !== DataSeries::TYPE_PIECHART) && ($chartType !== DataSeries::TYPE_PIECHART_3D) && ($chartType !== DataSeries::TYPE_DONUTCHART)) {
if ($chartType === DataSeries::TYPE_BUBBLECHART) {
$this->writeValueAxis($objWriter, $xAxisLabel, $chartType, $id2, $id1, $catIsMultiLevelSeries, $xAxis ?? new Axis());
} else {
$this->writeCategoryAxis($objWriter, $xAxisLabel, $id1, $id2, $catIsMultiLevelSeries, $xAxis ?? new Axis());
if ($plotArea->getDataTable()) {//この行を追加
$this->writeDataTable($objWriter);//この行を追加
}//この行を追加
}
$this->writeValueAxis($objWriter, $yAxisLabel, $chartType, $id1, $id2, $valIsMultiLevelSeries, $yAxis ?? new Axis());
if ($chartType === DataSeries::TYPE_SURFACECHART_3D || $chartType === DataSeries::TYPE_SURFACECHART) {
$this->writeSerAxis($objWriter, $id2, $id3);
}
}
/**
* Write DataTable
*
* @param XMLWriter $objWriter XML Writer
*/
private function writeDataTable($objWriter) {
$objWriter->startElement('c:dTable');
$objWriter->startElement('c:showHorzBorder');
$objWriter->writeAttribute('val', '1');
$objWriter->endElement();
$objWriter->startElement('c:showVertBorder');
$objWriter->writeAttribute('val', '1');
$objWriter->endElement();
$objWriter->startElement('c:showOutline');
$objWriter->writeAttribute('val', '1');
$objWriter->endElement();
$objWriter->startElement('c:showKeys');
$objWriter->writeAttribute('val', '1');
$objWriter->endElement();
$objWriter->endElement();
}
PhpSpreadsheet\Chart\PlotArea.php
Write Chart Plot Area.に下記を追加する。
/**
* PlotArea Data Table.
*
* @var bool
*/
private $dataTable = false;
/**
* Set Data Table.
* @param bool $dataTable
* @return PlotArea
*/
public function setDataTable($dataTable)
{
$this->dataTable = $dataTable;
return $this;
}
/**
* Get Data Table.
* @return bool
*/
public function getDataTable()
{
return $this->dataTable;
}
チャート生成時の指定方法
PlotAreaにsetDataTableをセット
$objPlotArea = new PlotArea($layout1, array($objSeries));
$objPlotArea->setDataTable(true);//この行を追加
- カテゴリー
- PHP