Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Latest commit

 

History

History
89 lines (76 loc) · 2.14 KB

README.md

File metadata and controls

89 lines (76 loc) · 2.14 KB

Repository abandoned 2020-11-27

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.

Charts

This package provides a PHP abstraction layer for multiple javascript chart libraries for Zend Framework 2. At the moment, following libraries are supported:

Installation

curl -s https://getcomposer.org/installer | php
php composer.phar install

Module Installation

Add to composer.json

"phpro/zf-charts": "~0.1"

Add module to application.config.php

return array(
    'modules' => array(
        'AssetManager',
        'Phpro\Chart',
        // other libs...
    ),
    // Other config
);

ChartJS

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

Line chart

$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);

Doughnut chart

$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);

View Helper

<?php echo $this->chartjs($this->chart, [
    'show_legend' => true,
    'width' => 900,
    'height' => 400,
]); ?>