Below is the default form of the constructor:
PHPGraphLib object constructor. $width and $height arguments are optional. Default width=400, height=300. Recommended width is at least 200 and recommended height is at least 225.
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.
The two other main, required functions are below:
Adds data to the graph. The array values will be the y-axis value. If the array has keys, the keys will be the corresponding x-axis values.
Creates and outputs the graph. Must be called last.
All other graph customization functions are below:
Sets the x-axis margin as a percentage of the height and the color or the x-axis.
By default, the x-axis margin is 8% of the width and black. Color may be specified as one of the supported colors, an RGB value comma separated string, or a hex value. You may also call the setupXAxis() function with only a false argument to hide the x-axis. You can also call it with just the first argument, or leave the percent argument as an empty string and call it with the color argument.
Sets the y-axis margin as a percentage of the height and the color or the y-axis.
By default, the y-axis margin is 8% of the width and black. Color may be specified as one of the supported colors, an RGB value comma separated string, or a hex value. You may also call the setupYAxis() function with only a false argument to hide the y-axis. You can also call it with just the first argument, or leave the percent argument as an empty string and call it with the color argument.
Sets the range of values to be displayed on the y-axis. This overrides the default automatic y-axis range and values that get shown on the graph. Examples of setRange() are shown below:
![]() |
![]() |
|
Default Range Handling |
With setRange(130,80) function. |
Note that setRange() has some limitations - The $max/$min variables are approximate. Sometimes PHPGraphLib may slightly alter these values when faced with non-rounded values.
Display values on the x-axis. Accepts either true or false arguments. Default value is true, the x-axis values are displayed.
Display values on the y-axis. Accepts either true or false arguments. Default value is true, the y-axis values are displayed.
Display values on the x-axis orientated horizontally. Accepts either true or false arguments. Default value is false, the y-axis values are vertically oriented.
![]() |
|
Horizontal X-Axis Values |
Display values on the x-axis orientated vertically. Accepts either true or false arguments. Default value is true, the y-axis values are vertically oriented.
![]() |
|
Vertical X-Axis Values |
Sets the text color used to display values on the both axis. Color may be specified as one of the supported colors, an RGB value comma separated string, or a hex value. Default text color is a dark gray.
Sets the text color used to display values on just the x-axis. Color may be specified as one of the supported colors, an RGB value comma separated string, or a hex value. Default color is a dark gray.
Sets the text color used to display values on just the y-Axis. Color may be specified as one of the supported colors, an RGB value comma separated string, or a hex value. Default color is a dark gray.
Sets and displays a title for the graph.
Sets the title color. Color may be specified as one of the supported colors, an RGB value comma separated string, or a hex value. Default title color is black.
Sets the location of the title across the top of the graph. Valid values are "left", "right", "center". Default title location is the center.
Display bars on the graph - i.e. displays a bar graph. Accepts either true or false arguments. Default value is true, the bars are displayed.
Sets the color of the bars on the graph. Color may be specified as one of the supported colors, an RGB value comma separated string, or a hex value. Default bar color is gray. PHPGraphLib will ignore this function if the setGradient() function is set.
If using multiple datasets, you may specify up to two additional colors. If you are using multiple datasets, but have not specifed more than one color, additional colors will be specified automatically.
Display an outline around each bar on the graph. Accepts either true or false arguments. Default value is true, the outline is displayed.
Sets the color of the outline of each bar on the graph. Color may be specified as one of the supported colors, an RGB value comma separated string, or a hex value. Default bar outline color is black.
Sets the colors for and enables the bars of the graph to be displayed as a gradient between two colors. Color arguments may be specified as one of the supported colors or as an RGB value comma separated string. By default, the gradient feature is not enabled.
If using multiple datasets, up to two more pairs of gradient colors may be specified. If you are using multiple datasets, but have not specifed more than one gradient color, additional gradient colors will be specified automatically.
Display the grid. Accepts either true or false arguments. Default value is true, the grid is displayed.
Display the grid. Accepts either true or false arguments. Default value is true, the grid is displayed.
Display the graph line. Accepts either true or false arguments. Default value is false, the graph line is not displayed.
Sets the line color of the graph lines, if enabled, on the graph. Color may be specified as one of the supported colors, an RGB value comma separated string, or a hex value. Default line color is a dark gray.
If multiple datasets are used, you can specify up to two additional line colors. If graph bars are disabled, and there are multiple datasets, but only one line color is specified, additional line colors will be generated automatically.
Display a circular data point on the graph for each value. Accepts either true or false arguments. Default value is false, data points are not displayed.
Sets the color of the data point circle, if enabled, on the graph. Color may be specified as one of the supported colors, an RGB value comma separated string, or a hex value. Default data point color is black.
Sets the diameter of the data point circle, if enabled on the graph. Default size is 6 pixels.
Display each numeric data value, as passed in the data value array, on the graph. Accepts either true or false arguments. Default value is false, data values are not displayed.
![]() |
Sets the color of the data value display, if enabled, on the graph. Color may be specified as one of the supported colors, an RGB value comma separated string, or a hex value. Default data value color is a dark gray.
Formats data points on both the y axis and the actual graph (if setDataPoints(true); is set). Current supported formats include "percent" which appends a % to the end of each value, "degrees" which appends a ° to the end of each value, and "comma" which groups values with commas (3,232,109). You can call as many setDataFormat() functions as you want.
If the format argument is not in the above list of supported formats, the value specified will be appended to the end of the data value displayed. For example if you have a data value of 23 and you call $graph->setDataFormat(" Apples"), the data value will be displayed as: 23 Apples.
Formats data points on both the y axis and the actual graph (if setDataPoints(true); is set) by adding currency symbols in front of the data value displayed. Currently the following formats are supported:
| dollar | $ |
| pound | £ |
| yen | ¥ |
| lira | £ |
If the currency argument is not in the above list, it will be appended to the front of the data value. For example if you have a data value of 2300 and you call $graph->setDataCurrency("*^* "), the data value will be displayed as: *^* 2300.
Displays a singular horizontal line to display a goal or y value needing emphasis. $color and $style arguments are optional. The default color is black if not specified and the default style is solid. Current possible values of the $style argument are "solid" and "dashed". Goal value must be within bounds of the maximum and minimum y-axis values. The setGoalLine() function can be called multiple times to add multiple goal lines, if needed.
![]() |
This function is deprecated in favor of specifying a color in the setGoalLine() function. Please use setGoalLine() in new implementations.
Sets the color of the goal line, if present. Color may be specified as one of the supported colors, an RGB value comma separated string, or a hex value. Default goal line color is black.
Display a legend with color swatches matching the corresponding colors on the graph. Accepts either true or false arguments. Default value is false, the legend is not displayed.
Sets the title of the dataset on the legend. If using more than one dataset, specify titles in the order of datasets specified in the addData() function.
Sets the background color of the legend, if present. Color may be specified as one of the supported colors, an RGB value comma separated string, or a hex value. Default legend background color is white.
![]() |
Sets text color in the legend. Color may be specified as one of the supported colors, an RGB value comma separated string, or a hex value. Default color is dark gray.
Sets border color of the legend. Color may be specified as one of the supported colors, an RGB value comma separated string, or a hex value. Default color is light gray.
Sets the border color of the color swatches in the legend. Color may be specified as one of the supported colors, an RGB value comma separated string, or a hex value. Default color is a dark gray.
Sets the background color for the graph. Color may be specified as one of the supported colors, an RGB value comma separated string, or a hex value. There is no need to enable the background by calling a boolean function - setting a color for it enables the background. Default background color is white.
The following is a list of colors supported in name by PHPGraphLib. The colors are from the W3C's list of 16 W3C Standard Colors.
| Color Name | Swatch | RGB Value | Color Name | Swatch | RGB Value |
| black | 0,0,0 | green | 0,128,0 | ||
| silver | 192,192,192 | lime | 0,255,0 | ||
| gray | 128,128,128 | olive | 128,128,0 | ||
| white | 255,255,255 | yellow | 255,255,0 | ||
| maroon | 128,0,0 | navy | 0,0,128 | ||
| red | 255,0,0 | blue | 0,0,255 | ||
| purple | 128,0,128 | teal | 0,128,128 | ||
| fuscia | 255,0,255 | aqua | 0,255,255 |