PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Sheldon Kennedy   NanoChart   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: NanoChart
Outputs a pie chart from a values array
Author: By
Last change:
Date: 2 months ago
Size: 1,497 bytes
 

Contents

Class file image Download

NanoChart

This PHP class builds a simple pie or doughnut chart as an SVG with a text legend.

Features

  1. Pass in an associative array of items and their amounts, and NanoChart creates the chart.
  2. Pass in your own colour palette to overide the default colours, or set your own hue value and NanoChart will create a palette.
  3. The legend can be to the right or below the chart (using CSS flexbox row or column).
  4. The output is HTML with inline styles.

Screenshot

screenshot

Usage

Prepare an associative array of names and amounts:

    $items = [
        'Monday' => 10,
        'Tuesday' => 20,
        'Wednesday' => 30
    ];

Instantiate NanoChart and pass in the array:

    $nanoChart = new NanoChart($items);

Customise with setters:

    $nanoChart->setSize(250); // width and height in pixels
    $nanoChart->setDirection('column'); // CSS flexbox direction options
    $nanoChart->setStyle('doughnut'); // change from a basic pie chart to a doughnut chart
    $nanoChart->setHue(150); // set the hue value for the colour palette
    $nanoChart->setPalette($palette); //pass in a simple array of colours to use for the items

Examples

See examples.php for different ways the class can be used.

Dependencies

Requires PHP 7.4 or later.

License

This project is licensed under the MIT License.

Acknowledgments

Feel free to contribute, report issues, or suggest improvements!