You are here

function chart_build in Google Chart Tools: Image Charts 5

Same name and namespace in other branches
  1. 6 chart.module \chart_build()
  2. 7 chart.module \chart_build()

Build chart query string.

Parameters

array $chart :

REQUIRED #chart_id #type #data

OPTIONAL #title #size #legends #labels #adjust_resolution #line_styles #grid_lines #shape_markers #data_colors #chart_fill #mixed_axis_labels #mixed_axis_label_styles #bar_size

Return value

mixed Query string or FALSE on failure.

2 calls to chart_build()
chart_copy in ./chart.module
Copies rendered chart image.
chart_render in ./chart.module
Renders a chart structure.

File

./chart.module, line 206
Google Charting API. Developed by Tj Holowaychuk

Code

function chart_build($chart) {
  $data = array();
  if (!strlen(trim($chart['#chart_id']))) {
    return FALSE;
  }
  if (!count($chart['#data']) || !is_array($chart['#data'])) {
    return FALSE;
  }

  // Chart alter hook
  foreach (module_implements('chart_alter') as $module) {
    $function = $module . '_chart_alter';
    $function($chart['#chart_id'], $chart);
  }

  // Adjust resolution
  if (isset($chart['#adjust_resolution'])) {
    if ($chart['#adjust_resolution'] === TRUE) {
      _chart_adjust_resolution($chart['#chart_id'], $chart['#data']);
    }
    elseif ($chart['#adjust_resolution']['#adjust'] = TRUE) {
      _chart_adjust_resolution($chart['#chart_id'], $chart['#data'], $chart['#adjust_resolution']['#max']);
    }
  }
  $data['chd'] = 't:' . _chart_encode_data($chart['#data']);
  _chart_append('cht', $chart['#type'], $data);
  _chart_append('chs', $chart['#size'], $data);
  _chart_append('chtt', $chart['#title'], $data);
  _chart_append('chl', $chart['#labels'], $data);
  _chart_append('chdl', $chart['#legends'], $data);
  _chart_append('chls', $chart['#line_styles'], $data);
  _chart_append('chg', $chart['#grid_lines'], $data);
  _chart_append('chm', $chart['#shape_markers'], $data);
  _chart_append('chco', $chart['#data_colors'], $data);
  _chart_append('chf', $chart['#chart_fill'], $data);
  _chart_append('chxt', $chart['#mixed_axis_labels'], $data);
  _chart_append('chxs', $chart['#mixed_axis_label_styles'], $data);
  _chart_append('chbh', $chart['#bar_size'], $data);
  return drupal_query_string_encode($data);
}