You are here

protected function Chartjs::buildOptions in Charts 8.3

Build the options.

Parameters

array $options: Options.

Return value

\Drupal\charts_chartjs\Settings\Chartjs\ChartjsOptions

1 call to Chartjs::buildOptions()
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 113

Class

Chartjs
Define a concrete class for a Chart.

Namespace

Drupal\charts_chartjs\Plugin\chart

Code

protected function buildOptions(array $options) {
  $chartjsOptions = new ChartjsOptions();
  $chartjsScales = new ChartjsScales();
  $chartjsStacking = new ChartjsStacking();
  $ticks = new ChartjsTicks();
  $tickOptions = new ChartjsTickConfigurationOptions();

  // Determines if chart is stacked.
  if (!empty($options['grouping']) && $options['grouping'] == TRUE) {
    $grouping = TRUE;
  }
  else {
    $grouping = FALSE;
  }
  $chartjsStacking
    ->setStacking($grouping);
  $chartjsScales
    ->setXAxes([
    $chartjsStacking,
  ]);
  $ticks
    ->setTicks($tickOptions);
  $ticks
    ->setStacked($grouping);
  $chartjsScales
    ->setYAxes([
    $ticks,
  ]);
  $chartjsOptions
    ->setScales($chartjsScales);
  $tooltip = new \stdClass();
  if ($options['tooltips'] == 'TRUE') {
    $tooltip->enabled = TRUE;
  }
  else {
    $tooltip->enabled = FALSE;
  }
  $chartjsOptions
    ->setTooltips($tooltip);

  // Set Legend.
  $chartjsOptions
    ->setLegend($this
    ->buildLegend($options));

  // Set Title.
  $chartjsOptions
    ->setTitle($this
    ->buildTitle($options));
  return $chartjsOptions;
}