You are here

protected function Chartjs::buildChartType in Charts 8.3

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

Parameters

array $options: Options.

Return value

string $type Type.

1 call to Chartjs::buildChartType()
Chartjs::buildVariables in modules/charts_chartjs/src/Plugin/chart/Chartjs.php
Creates a JSON Object formatted for C3 Charts JavaScript to use.

File

modules/charts_chartjs/src/Plugin/chart/Chartjs.php, line 34

Class

Chartjs
Define a concrete class for a Chart.

Namespace

Drupal\charts_chartjs\Plugin\chart

Code

protected function buildChartType($options) {
  switch ($options['type']) {
    case 'bar':
      $type = 'horizontalBar';
      break;
    case 'column':
      $type = 'bar';
      break;
    case 'spline':
      $type = 'line';
      break;
    case 'donut':
      $type = 'doughnut';
      break;
    case 'area':
      $type = 'line';
      break;
    case 'gauge':
      $type = 'linearGauge';
      break;
    default:
      $type = $options['type'];
      break;
  }
  if (isset($options['polar']) && $options['polar'] == 1) {
    $type = 'radar';
  }

  // May need to handle attachment type.
  // @todo: need to handle gauge (https://github.com/scottmcculloch/Chart.LinearGauge.js) and scatter.
  return $type;
}