Charts examples
Charts Excel examples, explained clearly.
Open a focused example to see the implementation path, copy-ready PHP, expected workbook behavior, and the production boundary that matters.
4examples in this category
21focused categories
5implementation paths
01Column ChartCreate a native column chart from category and value ranges.
+
Create a native column chart from category and value ranges.
addChart()<?php
use Mnb\PHPExcel\MnbExcel;
MnbExcel::fromArray($monthlySales)
->withHeader()
->addChart('column', 'Monthly Sales', [[
'name' => 'Sales',
'categories' => 'Sheet1!$A$2:$A$13',
'values' => 'Sheet1!$B$2:$B$13',
]], ['from' => 'D2', 'to' => 'L18'])
->save('column-chart.xlsx');02Line ChartPlot a sequence over time as a native line chart.
+
Plot a sequence over time as a native line chart.
addChart()<?php
use Mnb\PHPExcel\MnbExcel;
MnbExcel::fromArray($dailyTraffic)
->withHeader()
->addChart('line', 'Daily Traffic', [[
'name' => 'Visits',
'categories' => 'Sheet1!$A$2:$A$31',
'values' => 'Sheet1!$B$2:$B$31',
]], ['from' => 'D2', 'to' => 'L18'])
->save('line-chart.xlsx');03Pie ChartCreate a pie chart for a small set of mutually exclusive categories.
+
Create a pie chart for a small set of mutually exclusive categories.
addChart()<?php
use Mnb\PHPExcel\MnbExcel;
MnbExcel::fromArray($salesByCategory)
->withHeader()
->addChart('pie', 'Sales Mix', [[
'name' => 'Amount',
'categories' => 'Sheet1!$A$2:$A$6',
'values' => 'Sheet1!$B$2:$B$6',
]], [
'from' => 'D2',
'to' => 'K17',
'legend' => 'right',
'vary_colors' => true,
])
->save('pie-chart.xlsx');04Combo ChartPreserve a trusted template when one chart must combine different chart types or use a secondary axis.
+
Preserve a trusted template when one chart must combine different chart types or use a secondary axis.
preserveAdvancedObjectsFrom()<?php
use Mnb\PHPExcel\MnbExcel;
MnbExcel::fromArray($revenueAndMargin)
->withHeader()
->preserveAdvancedObjectsFrom('templates/revenue-combo-chart.xlsx')
->save('revenue-combo-chart-output.xlsx');Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue