You are here

function _fusioncharts_series in Charts 7

Convert all Series-level data.

Parameters

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

&$data: Array. The raw data.

Return value

String. The string presentation of series data

1 string reference to '_fusioncharts_series'
_fusioncharts_charts_render in fusioncharts/fusioncharts.inc
Implementation of hook_charts_render().

File

fusioncharts/fusioncharts.inc, line 155
@author Bruno Massa http://drupal.org/user/67164

Code

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

  // Convert the chat DATA into the FusionCharts way.
  // Since its a requirement to build the chart on FusionCharts, if the value
  // was not found, return nothing and stop the execution.
  foreach (element_children($data) as $series) {
    $series_data = array();
    foreach (element_children($data[$series]) as $values) {
      $serie_data = array(
        'value' => $data[$series][$values]['#value'],
      );
      if (isset($data[$series][$values]['#label'])) {
        $serie_data['label'] = $data[$series][$values]['#label'];
      }
      $series_data[] = $serie_data;
    }
    if (isset($data['#color'][$series])) {
      $options['color'] = substr($data['#color'][$series], 1);
    }
    $chart['value'][] = _fusioncharts_values('set', $series_data, $options);
    foreach (element_children($data[$series]) as $values) {
      $value_labels_temp[] = empty($data[$series][$value]['#label']) ? NULL : $data[$series][$value]['#label'];
    }

    // X labels
    $value_labels = array();
    $toogle = FALSE;
    foreach (array_keys($series_data) as $value) {
      if (empty($data[$series][$value]['#label'])) {
        $value_labels[] = '';
        $toogle = TRUE;
      }
      else {
        $value_labels[] = $data[$series][$value]['#label'];
        $toogle = TRUE;
      }
    }
    if (!empty($toogle) and empty($chart['categories'])) {
      $chart['value'][] = _fusioncharts_values('category', $value_labels);
      $chart['categories'] = TRUE;
    }
  }
}