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
21supported categories
5implementation paths
Monolithic library
Charts examples with copy-ready, production-minded PHP.
Each example identifies the exact methods it uses and can be opened independently from the right-side index.
- 4
- examples
- 2
- documented methods
addChart()<?php
declare(strict_types=1);
/*
Summary:
Create a native column chart from category and value ranges.
Implementation note:
Column charts are effective for comparing discrete categories.
*/
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');addChart()<?php
declare(strict_types=1);
/*
Summary:
Plot a sequence over time as a native line chart.
Implementation note:
Use true date cells and date number formats for time-based category axes.
*/
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');addChart()<?php
declare(strict_types=1);
/*
Summary:
Create a pie chart for a small set of mutually exclusive categories.
Implementation note:
Avoid pie charts with many categories or nearly equal values.
*/
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');preserveAdvancedObjectsFrom()<?php
declare(strict_types=1);
/*
Summary:
Preserve a trusted template when one chart must combine different chart types or use a secondary
axis.
Implementation note:
The direct chart builder creates one chart type per chart. Combo charts and advanced
secondary-axis layouts are best maintained in a template.
*/
use Mnb\PHPExcel\MnbExcel;
MnbExcel::fromArray($revenueAndMargin)
->withHeader()
->preserveAdvancedObjectsFrom('templates/revenue-combo-chart.xlsx')
->save('revenue-combo-chart-output.xlsx');No matching example found.Try a method name, task, or result.
Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue