如何使用phpSpreadsheet设置图表的宽度和高度

时间:2018-05-04 11:36:16

标签: charts phpspreadsheet

我试图设置phpSpreadsheet创建的Excel图表的大小。

我使用了以下代码,但布局设置似乎没有任何效果:

// Define chart position and size
$layout = new Layout();
$layout->setXPosition(10);
$layout->setYPosition(50);
$layout->setWidth(400);
$layout->setHeight(300);

//  Set the series in the plot area
$plotArea = new PlotArea($layout, [$series]);
//  Set the chart legend
$legend = new Legend(Legend::POSITION_RIGHT, null, false);

$title = new Title('Test');
$yAxisLabel = new Title('y');

//  Create the chart
$chart = new Chart(
    'chart1', // name
    $title, // title
    $legend, // legend
    $plotArea, // plotArea
    true, // plotVisibleOnly
    0, // displayBlanksAs
    null, // xAxisLabel
    $yAxisLabel  // yAxisLabel
);

1 个答案:

答案 0 :(得分:0)

没有明确的图表宽度和高度设置。相反,为图表区域定义左上角和右下角的单元格,如下所示:

$chart->setTopLeftPosition('A1');
$chart->setBottomRightPosition('M9');
$worksheet->addChart($chart);

参见图表示例,例如here

相关问题