You are here

protected function Chartjs::populateChartType 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::populateChartType()

Outputs a type that can be used by Chart.js.

Parameters

array $element: The given element.

Return value

string The generated type.

2 calls to Chartjs::populateChartType()
Chartjs::populateDatasets in modules/charts_chartjs/src/Plugin/chart/Library/Chartjs.php
Populate Dataset.
Chartjs::populateOptions in modules/charts_chartjs/src/Plugin/chart/Library/Chartjs.php
Populate options.

File

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

Class

Chartjs
Define a concrete class for a Chart.

Namespace

Drupal\charts_chartjs\Plugin\chart\Library

Code

protected function populateChartType(array $element) {
  switch ($element['#chart_type']) {
    case 'bar':
    case 'column':
      $type = 'bar';
      break;
    case 'area':
    case 'spline':
      $type = 'line';
      break;
    case 'donut':
      $type = 'doughnut';
      break;
    case 'gauge':

      // Gauge is currently not supported by Chart.js.
      $type = 'donut';
      break;
    default:
      $type = $element['#chart_type'];
      break;
  }
  if (isset($element['#polar']) && $element['#polar'] == 1) {
    $type = 'radar';
  }
  return $type;
}