You are here

Categories.php in Flot 8

File

flot_examples/src/Controller/Categories.php
View source
<?php

namespace Drupal\flot_examples\Controller;

use Drupal\Core\Controller\ControllerBase;

/**
 * Display a barchart.
 */
class Categories extends ControllerBase {

  /**
   * Function categories.
   */
  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;
  }

}

Classes

Namesort descending Description
Categories Display a barchart.