You are here

private function Chartjs::populateCategories in Charts 5.0.x

Same name and namespace in other branches
  1. 8.4 modules/charts_chartjs/src/Plugin/chart/Library/Chartjs.php \Drupal\charts_chartjs\Plugin\chart\Library\Chartjs::populateCategories()

Populate categories.

Parameters

array $element: The element.

array $chart_definition: The chart definition.

Return value

array Return the chart definition.

1 call to Chartjs::populateCategories()
Chartjs::preRender in modules/charts_chartjs/src/Plugin/chart/Library/Chartjs.php
Pre render.

File

modules/charts_chartjs/src/Plugin/chart/Library/Chartjs.php, line 230

Class

Chartjs
Define a concrete class for a Chart.

Namespace

Drupal\charts_chartjs\Plugin\chart\Library

Code

private function populateCategories(array $element, array $chart_definition) {
  $children = Element::children($element);
  $categories = [];
  foreach ($children as $child) {
    $type = $element[$child]['#type'];
    if ($type === 'chart_xaxis') {
      $categories = array_map('strip_tags', $element[$child]['#labels']);

      // Merge in axis raw options.
      if (!empty($element[$child]['#raw_options'])) {
        $categories = NestedArray::mergeDeepArray([
          $element[$child]['#raw_options'],
          $categories,
        ]);
      }
    }
  }
  $chart_definition['data']['labels'] = $categories;
  return $chart_definition;
}