You are here

public static function Util::createChartableData in Charts 8

Same name and namespace in other branches
  1. 8.4 src/Util/Util.php \Drupal\charts\Util\Util::createChartableData()
  2. 8.3 src/Util/Util.php \Drupal\charts\Util\Util::createChartableData()
  3. 5.0.x src/Util/Util.php \Drupal\charts\Util\Util::createChartableData()

Creates chart data to be used later by visualization frameworks

1 call to Util::createChartableData()
template_preprocess_views_view_charts in ./charts.module

File

src/Util/Util.php, line 54

Class

Util

Namespace

Drupal\charts\Util

Code

public static function createChartableData($data) {
  $chartData = array();
  $categories = array();
  $seriesData = array();
  for ($i = 0; $i < count($data[0]); $i++) {
    $seriesRowData = array(
      'name' => '',
      'color' => '',
      'data' => array(),
    );
    for ($j = 0; $j < count($data); $j++) {
      $categories[$j] = $data[$j][$i]['label_field'];
      $seriesRowData['name'] = $data[$j][$i]['label'];

      // $seriesRowData['name'] = $data[$j][$i]['label_field'];
      $seriesRowData['color'] = $data[$j][$i]['color'];
      array_push($seriesRowData['data'], (int) $data[$j][$i]['value']);
    }
    array_push($seriesData, $seriesRowData);
  }
  $chartData[0] = $categories;
  $chartData[1] = $seriesData;
  return $chartData;
}