You are here

public function Canvas::content in Flot 8

Zooming.

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

File

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

Class

Canvas
Display a chart in canvas mode.

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 = [
    'canvas' => TRUE,
    'xaxes' => [
      [
        'mode' => "time",
      ],
    ],
    'yaxes' => [
      [
        'min' => 0,
      ],
      [
        'position' => "right",
        'alignTicksWithAxis' => 1,
        'tickFormatter' => 'function',
      ],
    ],
    'legend' => [
      'position' => "sw",
    ],
  ];
  $text = [];
  $text[] = $this
    ->t('This example uses the same dataset (raw oil price in US $/barrel of crude oil vs. the exchange rate from US $ to €) as the multiple-axes example, but uses the canvas plugin to render axis tick labels using canvas text.');
  $text[] = [
    [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Enable canvas text'),
    ],
  ];
  $output[] = [
    '#type' => 'flot',
    '#theme' => 'flot_examples',
    '#data' => $data,
    '#options' => $options,
    '#text' => $text,
    '#attached' => [
      'library' => [
        'flot_examples/canvas',
      ],
    ],
  ];
  return $output;
}