Chart API Hooks

Last updated on
30 April 2025

Below is a list of hooks available in the Chart module. They can be used for modifying the chart definitions (stored in $chart, an associative array defining a chart) directly for customizing a particular chart.

hook_chart_alter()
Alter a chart before it is rendered.

Usage

...

Parameters

  • $chart_id - ...
  • $chart - ...

Example

 function hook_chart_alter($chart_id, &$chart) {
   if ($chart_id == 'node_counts'){
     $chart['#size'] = chartapi_size(300, 200);  
   }
 }
hook_chart_color_schemes()
Extend the definition of chart color schemes.

Usage

Assoc arrays can be used to pre-map colors to a specific $content_id.
Attention, do not use the pound sign (#) for hex color values.

Parameters

  • $colors - ...

Example

function hook_chart_color_schemes(&$colors) {
  $colors['watchdog_severity'] = array(
      '0000FF',
      'FFFF00',
      'FF0000',
    );   
}

function hook_chart_color_schemes(&$colors) {
  $colors['watchdog_severity'] = array(
      'Notice'  => '0000FF',
      'Warning' => 'FFFF00',
      'Error'   => 'FF0000',
    );   
}
hook_chart_color_schemes_alter()
Alter the definition of chart color schemes.

Usage

...

Parameters

  • $schemes - ...

Example

 function hook_chart_color_schemes_alter(&$schemes) {
  $schemes['default'] = array(
  'FFFFFF',
  '000000',
    );   
}
hook_chart_views_alter()
Alter a views chart before it is rendered.

Usage

This (chart_views) hook is based on the views context, and executed before chart_alter() so additional changes may be made in chart_alter().

Parameters

  • $chart - An associative array defining a chart.
  • $view - The name of the view to which the chart belongs.
  • $display - The name of the display to which the chart belongs.

Example

function hook_chart_views_alter(&$chart, $view, $display) {
 $chart['#title'] .= ' (altered)';
}
hook_chart_post_build()
Append custom charting library parameters.

Usage

...

Parameters

  • $chart_id - ...
  • $chart - ...
  • $data - ...

Example

function hook_chart_post_build($chart_id, $chart, &$data) {
  if ($chart['#scale']) {
    $data['chds'] = implode(',', $chart['#scale']);
  }
}

Use cases

Here are some sample requests to illustrate some use cases for using some of these hooks:

hook_chart_post_build

Add more such issues here if you find any ...

And some details about that hook ...


Note (1): This documentation is now an enhanced version of what used to be at Available Hooks. That content over there has been integrated entirely now, and shouldn't contain anymore info that is not around here ....

Note (2): Feel free to further refine this page ... use the button here to do so ... edit

Help improve this page

Page status: Not set

You can: