PHPGraphLibPie Function Reference

PHPGraphLibPie is an extension of the original PHPGraphLib that allows you to make pie charts using the existing PHPGraphLib framework. For an example of setup and usage, see Tutorial #3: PHPGraphLibPie Extension - Creating a Pie Chart.

PHPGraphLibPie inherits many of the same functions as PHPGraphLib. There is a list of inherited functions at the bottom of this page.

Anatomy of a PHPGraphLibPie Chart

Anatomy of a PHPGraphLibPie Chart

Below is the default form of the constructor:

Constructor

PHPGraphLibPie( int $width, int $height, [string $filename] )
required
  • $graph=new PHPGraphLibPie(600,400);
  • $graph=new PHPGraphLibPie(600,400, "image.png");

PHPGraphLibPie object constructor. $width and $height arguments are optional. Default width=400, height=300.

If you specify the optional filename argument, PHPGraphLib will not display to the screen, but instead create a .png file in the same directory as the script where PHPGraphLib is being called.


PHPGraphLibPie Specific Functions

setDataLabels( boolean $labels )
  • $graph->setDataLabels(false);

Display % data labels by each section of the pie/ Accepts either true or false arguments. Default value is true, data labels are displayed.

setPrecision( int $digits )
required
  • $graph->setPrecision(2);

Sets the number of significant digits to be displayed on the graph if the setDataLabels() function is true. Default is 0 significant digits, meaning that hey data labels are whole numbers.

setLabelTextColor( string $title )
required
  • $graph->setLabelTextColor("maroon");
  • $graph->setLabelTextColor("0,0,200");

Sets the text color of the display % labels on the pie chart. Color may be specified as one of the supported colors or as an RGB value comma separated string. Default color is a black.

PHPGraphLibPie also inherits some functions from the PHPGraphLib class. These functions are:

  • addData()
  • createGraph()
  • setBackgroundColor()
  • setTitle()
  • setTitleColor()

As of PHPGraphLib 2.0, PHPGraphLibPie also inherits the following functions that used to be just included in PHPGraphLibPie.

  • setLegend()
  • setLegendColor()
  • setLegendTextColor()
  • setLegendOutlineColor()
  • setSwatchOutlineColor()

For usage, please refer to the main PHPGraphLib Function Reference.

Supported Colors

In addition to supporting all the colors built into PHPGraphLib, PHPGraphLibPie also supports the following colors in name:

  • pastel_orange_1
  • pastel_orange_2
  • pastel_blue_1
  • pastel_blue_2
  • pastel_green_1
  • pastel_green_2
  • clay
  • pastel_yellow
  • pastel_purple
  • brown

The colors used in the pie slices are automatically drawn from a list that includes these colors. Lighter pastel colors, are easier on the eyes when used in a pie chart situation.