You are here

function _google_charts_chart in Charts 7

Same name and namespace in other branches
  1. 6 google_charts/google_charts.inc \_google_charts_chart()

Convert all Chart-level data.

Parameters

&$chart: Array. The array that will be converted into a string for Google Charts

&$data: Array. The raw data.

Return value

String. The string presentation of series data

1 call to _google_charts_chart()
_google_charts_render in google_charts/google_charts.inc
Implementation of hook_charts_render().

File

google_charts/google_charts.inc, line 31
@author Bruno Massa http://drupal.org/user/67164

Code

function _google_charts_chart(&$chart, &$data) {

  // Convert the chat TYPE into the Google Chart way.
  // Since its a requirement to build the chart on Google, if the value
  // was not found, return nothing and stop the execution.
  $options = _google_charts($data['#type']);
  if (empty($options['typecode'])) {
    return t('This type is not possible using %chartplugin', array(
      '%chartplugin' => 'Google Chart',
    ));
  }
  if ($data['#type'] == 'pie2D' and count(element_children($data)) > 1) {
    $chart[] = 'cht=pc';
  }
  else {
    $chart[] = 'cht=' . $options['typecode'];
  }

  // Convert the chat SIZE into the Google Chart way.
  // Since its a requirement to build the chart on Google, if the value
  // was not found, return nothing and stop the execution.
  if (empty($data['#width']) or empty($data['#height'])) {
    return t('Height and Width are required');
  }
  $chart[] = 'chs=' . $data['#width'] . 'x' . $data['#height'];

  // Add Title and Description to the chart
  if (!empty($data['#title'])) {
    $chart[] = 'chtt=' . $data['#title'];
  }

  // Chart background color. Since the default color
  // is white (#ffffff), only different colors are considered
  if (!empty($data['#color']['background']) and $data['#color']['background'] != '#ffffff') {
    $chart[] = 'chf=bg,s,' . substr($data['#color']['background'], 1);
  }
  return;
}