Blog Help & Support Contact About Login

 Show Nav

PHP Graphs Wrapper

Use this wrapper to make and customize interactive PHP graphs with ZingChart. No JavaScript required.

Installation

You can easily install ZingChart via GitHub or Composer.

  • GitHub

    git clone https://github.com/zingchart/ZingChart-PHP.git
  • Composer

    composer require zingchart/php_wrapper

Basics

You can quickly render charts and graphs easily with these simple steps:

$zc = new ZC(“myGraph”);
$zc->setChartType(‘area’);
$zc->setSeriesData(0, [1,4,2,6,4]);
$zc->render();
A simple area chart made with PHP

Customizable

Quick start with the basics, or use the full functionality options for more extensive customizations with the ZingChart library. These options refer to ‘levels 2 and 3’ in our GitHub’s readme file.

To set an individual attribute or node you may use the following ‘level 2’ function which employs the dot notation syntax:

$zc->setConfig(“legend.header.text”, “Apples vs Oranges”);

With the example above and adding this one line of code we get the following chart.

A simple area chart with a legend, created with PHP

There is another function that you can use if you are already familiar with JSON syntax. This is the ‘level 3’ function. This function accepts a string or json object and will overwrite your previously set configuration:

$config = <<< EOT
{
  "type": "area",
  "title": {
    "text": "Bushels"
  },
  "subtitle": {
    "text": "Average Consumed"
  },
  "legend":{
    "header":{
      "background-color":"red",
      "text": "Apples and Oranges"
    },
    "marker":{
      "border-color":"orange",
      "border-width":"3px",
      "shadow-angle":"115"
    }
  },
  "scaleX": {
    "label": {
      "text": "Days"
    }
  },
  "scaleY": {
    "label": {
      "text": "# Bushels"
    }
  },
  "series":[
    {
      "values":[33,45,27,32,15],
      "text":"Apples"
    },
    {
      "values":[1,5,9,3,7],
      "text":"Oranges"
    }
  ]
}
EOT;

$zc->trapdoor($config);
$zc->render();

This will produce:

An area chart with a title, legend, and scales, all made in PHP

Fully Capable

This is simply a wrapper around ZingChart. It allows users to use all the capabilities of the library to quickly build beautiful interactive charts and graphs in PHP.

Responsive

If you set your graph’s width and/or height attribute(s) to a percentage, then they will scale nicely with your browser window size. To see this effect, click on these PHP graph demos and then resize your browser window by dragging on one of the corners of the window.

Next Steps

Want to learn more about the PHP graph wrapper? Want to start using it?

Fork on GitHub Read our Blog Post