public function charts ()
{
// Define data series values (replace with your actual data ranges)
$dataSeriesLabels = [
new DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // Example label
];
$xAxisTickValues = [
new DataSeriesValues('String', 'Worksheet!$B$2:$B$8', null, 2), // Example categories
];
$dataSeriesValues = [
new DataSeriesValues('Number', 'Worksheet!$C$2:$C$8', null, 7), // Example values
];
// Create the data series
$series = new DataSeries(
DataSeries::TYPE_BARCHART, // Chart type
DataSeries::GROUPING_CLUSTERED,
range(0, count($dataSeriesValues) - 1),
$dataSeriesLabels,
$xAxisTickValues,
$dataSeriesValues
);
// Create the plot area and legend
$plotArea = new PlotArea(new Layout(), [$series]);
$legend = new Legend(Legend::POSITION_RIGHT, null, false);
// Create the chart
$chart = new Chart(
'chart1', // Chart name
null, // Title
$legend,
$plotArea,
true, // plotVisibleOnly
0, // displayBlanksAs
null, // xAxisLabel
null // yAxisLabel
);
// Position the chart in the Excel sheet
$chart->setTopLeftPosition('E1');
$chart->setBottomRightPosition('L15');
return [$chart];
}
Mar 30, 2026
3
Level 1
Using Laravel Excel to insert a Chart into an Excel Worksheet
PHP 8.4
"laravel/framework": "^12.31",
"laravel/sanctum": "^4.2",
"laravel/ui": "^4.6",
May I please pointed to an example of a Worksheet Export that generates a spreadsheet with an embedded chart?
I presume this is the documentation I should be looking at. https://docs.laravel-excel.com/
The examples found here are throwing errors. https://docs.laravel-excel.com/3.1/exports/charts.html#charts
This snippet I found generates an empty chart or no chart at all.
Please or to participate in this conversation.