You are here

function charts_google_render_charts in Charts 8

Creates a JSON Object formatted for Google charts to use

Parameters

array $categories:

array $seriesData:

Return value

json|string

1 call to charts_google_render_charts()
template_preprocess_views_view_charts in ./charts.module

File

modules/charts_google/charts_google.module, line 32
Charts module integration with Google Charts library.

Code

function charts_google_render_charts($categories = array(), $seriesData = array()) {
  $dataTable = array();
  $dataTableHeader = array();
  for ($r = 0; $r < count($seriesData); $r++) {
    array_push($dataTableHeader, $seriesData[$r]['name']);
  }
  for ($j = 0; $j < count($categories); $j++) {
    $rowDataTable = [];
    for ($i = 0; $i < count($seriesData); $i++) {
      $rowDataTabletemp = $seriesData[$i]['data'][$j];
      array_push($rowDataTable, $rowDataTabletemp);
    }
    array_unshift($rowDataTable, $categories[$j]);
    array_push($dataTable, $rowDataTable);
  }
  $dataTableHeader = array();
  for ($r = 0; $r < count($seriesData); $r++) {
    array_push($dataTableHeader, $seriesData[$r]['name']);
  }
  array_unshift($dataTableHeader, 'label');
  array_unshift($dataTable, $dataTableHeader);
  return json_encode($dataTable);
}