You are here

protected function Chartjs::buildGaugeOptions in Charts 8.3

Build the scale color ranges.

Parameters

array $options: Options.

Return value

array $scaleColorRanges Scale color ranges.

1 call to Chartjs::buildGaugeOptions()
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 84

Class

Chartjs
Define a concrete class for a Chart.

Namespace

Drupal\charts_chartjs\Plugin\chart

Code

protected function buildGaugeOptions(array $options) {
  $scaleColorRanges = [];
  $scaleColorRanges[0] = new \stdClass();
  $scaleColorRanges[1] = new \stdClass();
  $scaleColorRanges[2] = new \stdClass();

  // Red.
  $scaleColorRanges[0]->start = isset($options['red_from']) ? $options['red_from'] : '';
  $scaleColorRanges[0]->end = isset($options['red_to']) ? $options['red_to'] : '';
  $scaleColorRanges[0]->color = '#ff000c';

  // Yellow.
  $scaleColorRanges[1]->start = isset($options['yellow_from']) ? $options['yellow_from'] : '';
  $scaleColorRanges[1]->end = isset($options['yellow_to']) ? $options['yellow_to'] : '';
  $scaleColorRanges[1]->color = '#ffff00';

  // Green.
  $scaleColorRanges[2]->start = isset($options['green_from']) ? $options['green_from'] : '';
  $scaleColorRanges[2]->end = isset($options['green_to']) ? $options['green_to'] : '';
  $scaleColorRanges[2]->color = '#008000';
  return $scaleColorRanges;
}