Skip to main content
Easy Digital Downloads Documentation
Documentation, Reference Materials, and Tutorials for Easy Digital Downloads

EDD_Graph

The EDD_Graph class, introduced in EDD version 1.9, is used for easily building graphs of data. For example, the earnings / sales reports graphs seen in Downloads → Reports are created using EDD_Graph. The class can be used by extensions to quickly graph any data set.


A simple example looks like this:

$data = array(
	'Your Graph Label Here' => array(
		array( 1, 5 ),
		array( 3, 8 ),
		array( 10, 2 )
	),
	'Second Label Here' => array(
		array( 1, 7 ),
		array( 4, 5 ),
		array( 12, 8 )
	)
);
$graph = new EDD_Graph( $data );
$graph->display();

Each inner array represents a data point on the graph and should be structured like this:

array( 'value on x axis', 'value on y axis' )

Graphs can contain one one or more lines. To add multiple lines, simply add additional inner arrays, as shown in the example above.

Along with the data points, EDD_Grap allows you to control various options of the graph by using the set() method. For example:

// Example with options set to other than default:
$data = array(
    'Line Label' => array(
        array( 1, 5 ),
        array( 3, 8 ),
        array( 10, 2 )
    ),
    'Second Line Label' => array(
        array( 1, 7 ),
        array( 4, 5 ),
        array( 12, 8 )
    )
);
$graph = new EDD_Graph( $data );
$graph->set( 'bgcolor', '#000' );
$graph->set( 'color', '#fff' );
$graph->display();

The available options are:

  • y_mode
  • x_mode
  • y_decimals
  • x_decimals
  • y_position
  • time_format
  • ticksize_unit
  • ticksize_num
  • multiple_y_axes
  • bgcolor
  • bordercolor
  • color
  • borderwidth
  • bars
  • lines
  • points

See the Flot API reference for the possible values each of these can receive.

Note, if you want to display a graph on the front end, you will need to include includes/admin/reporting/class-edd-graph.php first.