You are here

public function AxesMultiple::content in Flot 8

Multiple Axes.

1 string reference to 'AxesMultiple::content'
flot_examples.routing.yml in flot_examples/flot_examples.routing.yml
flot_examples/flot_examples.routing.yml

File

flot_examples/src/Controller/AxesMultiple.php, line 15

Class

AxesMultiple
Displays a graph to demonstrate multiple axes.

Namespace

Drupal\flot_examples\Controller

Code

public function content() {
  $oilprices = $this::getData('OilData.txt');
  $exchangerates = $this::getData('ExchangeData.txt');
  $data[] = [
    'data' => $oilprices,
    'label' => "Oil price (\$)",
  ];
  $data[] = [
    'data' => $exchangerates,
    'label' => "USD/EUR exchange rate",
    'yaxis' => 2,
  ];
  $options = [
    'xaxes' => [
      [
        'mode' => "time",
      ],
    ],
    'yaxes' => [
      [
        'min' => 0,
      ],
    ],
    'legend' => [
      'position' => "sw",
    ],
  ];
  $text = [];
  $text[] = $this
    ->t('Multiple axis support showing the raw oil price in US $/barrel of crude oil vs. the exchange rate from US $ to €.');
  $text[] = $this
    ->t('As illustrated, you can put in multiple axes if you need to. For each data series, simply specify the axis number. In the options, you can then configure where you want the extra axes to appear.');
  $text[] = $this
    ->t('Position axis <button>left</button> or <button>right</button>.');
  $output[] = [
    '#type' => 'flot',
    '#theme' => 'flot_examples',
    '#data' => $data,
    '#options' => $options,
    '#text' => $text,
    '#attached' => [
      'library' => [
        'flot_examples/axes_multiple',
      ],
    ],
  ];
  return $output;
}