Developing Additional Charts_Graphs Implementations
Last updated on
30 April 2025
There're several things that a module needs to do, to provide additional implementations to Charts & Graphs module:
- Implement hook_chartgraph_provider().
Let's say you are implementing a charting engine called: Pinocchio. Your hook must return object (not array! Notice transformation before the return) that has the following structure:
function pinocchio_chartgraph_provider() { $provider = array( 'path' => dirname(__FILE__) . '/pinocchio.class.inc', //must be full path 'clazz' => 'Pinocchio', //implementation class' name 'name' => 'pinocchio', //name used when invoking through a factroy method 'nice_name' => 'Charts: Pinocchio', 'chart_types' => array( 'line' => t('Line'), 'bar' => t('Bar'), 'pie' => t('Pie'), 'area' => t('Area'), ), ); // Array was used for convenience of definition. We need to return an object return (object) $provider; } - Implement a sub-class of ChartsGraphsCanvas class:
class Pinocchio extends ChartsGraphsCanvas { var $type = 'line'; var $width = 450; var $height = 200; var $title = ''; public function set_data($rows, $x_labels) { $this->series = $rows; $this->x_labels = $x_labels; } public function get_chart() { //-- some logic that implements engine and produces HTML return $html; } }
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion