Php 如何固定图表y轴的初始值
当(分组的)第一条的尺寸超过某个阈值(在本例中为25)时,y轴不是从值0开始,而是从任意值开始,在本例中为23。 同样的情况也会发生在更多条上,但值不同这取决于它们的组合方式。 有没有办法确定轴的起始值 下面是复制问题的代码Php 如何固定图表y轴的初始值,php,phpspreadsheet,phpoffice,Php,Phpspreadsheet,Phpoffice,当(分组的)第一条的尺寸超过某个阈值(在本例中为25)时,y轴不是从值0开始,而是从任意值开始,在本例中为23。 同样的情况也会发生在更多条上,但值不同这取决于它们的组合方式。 有没有办法确定轴的起始值 下面是复制问题的代码 <?php require_once(__DIR__ . '/../../../cron/vendor/autoload.php'); use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpr
<?php
require_once(__DIR__ . '/../../../cron/vendor/autoload.php');
use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
$spreadsheet = new Spreadsheet();
/**********************************************************************************/
$arrayTable = [
['a',26,5,0,0,0]
];
$spreadsheet->getActiveSheet()->fromArray(
$arrayTable,
null,
'A4',
true
);
$labels = ['range1', 'range2', 'range3', 'range4', 'range5'];
$dataSeriesLabels = [];
foreach ($labels as $label) {
$dataSeriesLabels[] = new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $label, null, 1);
}
$dataSource = 'Worksheet!$A$4:$A$4';
$xAxisTickValues = [
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $dataSource, null, 1),
];
$dataSeriesValues = [];
$cols = ['B','C','D','E', 'F'];
foreach ($cols as $col) {
$dataSource = 'Worksheet!$' . $col . '$4:$' . $col . '$4';
$dataSeriesValues[] = new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, $dataSource, null, $count);
}
$series = new DataSeries(
DataSeries::TYPE_BARCHART, // plotType
DataSeries::GROUPING_STACKED, // plotGrouping
range(0, count($dataSeriesValues) - 1), // plotOrder
$dataSeriesLabels, // plotLabel
$xAxisTickValues, // plotCategory
$dataSeriesValues // plotValues
);
$series->setPlotDirection(DataSeries::DIRECTION_BAR);
$layout = null;
$plotArea = new PlotArea($layout, [$series]);
$legend = new Legend( Legend::POSITION_RIGHT, null, false);
$title = new Title('TEST');
$yAxisLabel = new Title('');
$chart = new Chart(
'test', // name
$title, // title
$legend, // legend
$plotArea, // plotArea
true, // plotVisibleOnly
'gap', // displayBlanksAs
null, // xAxisLabel
$yAxisLabel // yAxisLabel
);
$chart->setTopLeftPosition('H1');
$chart->setBottomRightPosition('R18');
$spreadsheet->getActiveSheet()->addChart($chart);
// Save Excel 2007 file
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true);
$writer->save('test.xlsx');