public static function Util::createChartableData in Charts 8
Same name and namespace in other branches
- 8.4 src/Util/Util.php \Drupal\charts\Util\Util::createChartableData()
- 8.3 src/Util/Util.php \Drupal\charts\Util\Util::createChartableData()
- 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()
File
- src/
Util/ Util.php, line 54
Class
Namespace
Drupal\charts\UtilCode
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;
}