You are here

protected function Chartjs::buildChartType in Charts 8.4

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

Parameters

array $options: The options.

Return value

string The generated type.

File

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

Class

Chartjs
Define a concrete class for a Chart.

Namespace

Drupal\charts_chartjs\Plugin\chart\Library

Code

protected function buildChartType(array $options) {
  switch ($options['type']) {
    case 'bar':
      $type = 'horizontalBar';
      break;
    case 'column':
      $type = 'bar';
      break;
    case 'area':
    case 'spline':
      $type = 'line';
      break;
    case 'donut':
      $type = 'doughnut';
      break;
    case 'gauge':

      // Setting this, but gauge is currently not supported by Chart.js.
      $type = 'gauge';
      break;
    default:
      $type = $options['type'];
      break;
  }
  if (isset($options['display']['polar']) && $options['display']['polar'] == 1) {
    $type = 'radar';
  }
  return $type;
}