This repository has been archived since we are not using it anymore internally. Feel free to use it AS-IS, we won't be providing any support anymore.
This package provides a PHP abstraction layer for multiple javascript chart libraries for Zend Framework 2. At the moment, following libraries are supported:
- Chart.js (Lines, Doughnuts)
curl -s https://getcomposer.org/installer | php
php composer.phar install
"phpro/zf-charts": "~0.1"
return array(
'modules' => array(
'AssetManager',
'Phpro\Chart',
// other libs...
),
// Other config
);
The API of the PHP library works exactly the same as the javascript API. More information about the configurable options can be found in the official documentation
$options = new LineOptions(['animation' => false]);
$data = new LineData();
$data->setLabels(['January', 'February', 'March', 'April', 'May', 'June', 'July']);
$data->addDataset(new LineDataset([
'label' => 'My first dataset',
'fillColor' => 'rgba(220,220,220,0.2)',
'strokeColor' => 'rgba(220,220,220,1)',
'pointColor' => 'rgba(220,220,220,1)',
'pointStrokeColor' => '#fff',
'pointHighlightFill' => '#fff',
'pointHighlightStroke' => 'rgba(220,220,220,1)',
'data' => [65, 59, 80, 81, 56, 55, 40]
]));
$chart = new LineChart($options, $data);
$options = new DoughnutOptions(['animation' => false]);
$data = new DoughnutData();
$data->addDataset(new DoughnutDataset([
'label' => 'label 1',
'value' => 50,
'color' => 'green',
'highlight' => 'green',
]));
$data->addDataset(new DoughnutDataset([
'label' => 'label 2',
'value' => 50,
'color' => 'red',
'highlight' => 'red',
]));
$chart = new DoughnutChart($options, $data);
<?php echo $this->chartjs($this->chart, [
'show_legend' => true,
'width' => 900,
'height' => 400,
]); ?>