You are here

public function Categories::content in Flot 8

Function categories.

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

File

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

Class

Categories
Display a barchart.

Namespace

Drupal\flot_examples\Controller

Code

public function content() {
  $options = [
    "series" => [
      "bars" => [
        "show" => TRUE,
        "barWidth" => 0.6,
        "align" => "center",
      ],
    ],
    "xaxis" => [
      "mode" => "categories",
      "ticklength" => 0,
    ],
  ];
  $data[] = [
    [
      $this
        ->t('January'),
      10,
    ],
    [
      $this
        ->t('February'),
      8,
    ],
    [
      $this
        ->t('March'),
      4,
    ],
    [
      $this
        ->t('April'),
      13,
    ],
    [
      $this
        ->t('May'),
      17,
    ],
    [
      $this
        ->t('June'),
      9,
    ],
  ];
  $text = $this
    ->t('With the categories plugin you can plot categories/textual data easily.');
  $output['flot'] = [
    '#type' => 'flot',
    '#data' => $data,
    '#options' => $options,
    '#theme' => 'flot_examples',
    '#text' => [
      $text,
    ],
  ];
  return $output;
}