PHPSReadSheet和Excel图表,Y轴位于错误位置
我正在尝试使用PHPSReadSheet在Excel中创建单个系列条形图或折线图。我无法使Y轴在正确的位置。无论是直线图还是条形图,Y轴都会在图表中的随机点上显示。这是我的代码,主要取自示例代码PHPSReadSheet和Excel图表,Y轴位于错误位置,excel,charts,phpspreadsheet,Excel,Charts,Phpspreadsheet,我正在尝试使用PHPSReadSheet在Excel中创建单个系列条形图或折线图。我无法使Y轴在正确的位置。无论是直线图还是条形图,Y轴都会在图表中的随机点上显示。这是我的代码,主要取自示例代码 // Set the Labels for each data series we want to plot $label=$sheetname."!\$H\$1"; $dataSeriesLabels = [ new DataSeriesValues(Data
// Set the Labels for each data series we want to plot
$label=$sheetname."!\$H\$1";
$dataSeriesLabels = [
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $label, null, 1),
];
// Set the X-Axis Labels
$xrange=$sheetname."!\$C\$2:\$C\$".$lastrow;
$xAxisTickValues = [
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $xrange, null, $lastrow),
];
// Set the Data values for each data series we want to plot
$data=$sheetname."!\$H\$2:\$H\$".$lastrow;
$dataSeriesValues = [
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, $data, null, $lastrow),
];
// Build the dataseries
$series = new DataSeries(
DataSeries::TYPE_BARCHART, // plotType
DataSeries::GROUPING_CLUSTERED, // plotGrouping
range(0, count($dataSeriesValues) - 1), // plotOrder
$dataSeriesLabels, // plotLabel
$xAxisTickValues, // plotCategory
$dataSeriesValues // plotValues
);
// Set the series in the plot area
$plotArea = new PlotArea(null, array($series));
// Set the chart legend
$legend = new Legend(Legend::POSITION_RIGHT, null, false);
$title = new Title('Labor');
$xAxisLabel = new Title('Part Number');
$yAxisLabel = new Title('Minutes');
// Create the chart
$chart = new Chart(
'chart1', // name
$title, // title
$legend, // legend
$plotArea, // plotArea
true, // plotVisibleOnly
0, // displayBlanksAs
$xAxisLabel, // xAxisLabel
$yAxisLabel // yAxisLabel
);
// Set the position where the chart should appear in the worksheet
$chart->setTopLeftPosition('A17');
$chart->setBottomRightPosition('N34');
// Add the chart to the worksheet
$sheet->addChart($chart);
上述代码生成以下图表:
我对线形图也有同样的问题。如何使Y轴值移动到左侧的适当位置?我在一些PHPExel文档中找到了答案。我刚刚添加了一个X轴和Y轴样式
$yaxis = new Axis();
$xaxis = new Axis();
$yaxis->setAxisOptionsProperties('low', null, null, null, null, null, -20, 20, null, null);
$yaxis->setLineParameters('FFFFFF',100,Axis::EXCEL_COLOR_TYPE_ARGB);
$xaxis->setAxisOptionsProperties('low', null, null, null, null, null, 0, 0, null, null);
然后将这些值添加到我的图表中
// Create the chart
$chart = new Chart(
'chart1', // name
$title, // title
$legend, // legend
$plotArea, // plotArea
true, // plotVisibleOnly
0, // displayBlanksAs
$xAxisLabel, // xAxisLabel
$yAxisLabel, // yAxisLabel
$yaxis,
$xaxis
);