You are here

public function AxesTime::content in Flot 8

Time Axes.

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

File

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

Class

AxesTime
Display a chart to demontrate date/time handling on the axes.

Namespace

Drupal\flot_examples\Controller

Code

public function content() {
  $d[] = $this::getData('CO2.txt');
  $options = [
    "xaxis" => [
      "mode" => "time",
    ],
  ];
  $text = [];
  $text[] = $this
    ->t('Monthly mean atmospheric CO<sub>2</sub> in PPM at Mauna Loa, Hawaii (source: <a href=":one">NOAA/ESRL</a>).', [
    ':one' => 'http://www.esrl.noaa.gov/gmd/ccgg/trends/',
  ]);
  $text[] = $this
    ->t('If you tell Flot that an axis represents time, the data will be interpreted as timestamps and the ticks adjusted and formatted accordingly.');
  $text[] = [
    [
      '#type' => 'button',
      '#value' => $this
        ->t('Whole Period'),
      '#attributes' => [
        'id' => [
          'whole',
        ],
      ],
      '#label' => $this
        ->t('Zoom to:'),
    ],
    [
      '#type' => 'button',
      '#value' => $this
        ->t('1990-2000'),
      '#attributes' => [
        'id' => [
          'nineties',
        ],
      ],
    ],
    [
      '#type' => 'button',
      '#value' => $this
        ->t('1996-2000'),
      '#attributes' => [
        'id' => [
          'latenineties',
        ],
      ],
    ],
  ];
  $text[] = [
    [
      '#type' => 'button',
      '#value' => $this
        ->t('1999 by quarter'),
      '#attributes' => [
        'id' => [
          'ninetyninequarters',
        ],
      ],
      '#label' => $this
        ->t('Zoom to:'),
    ],
    [
      '#type' => 'button',
      '#value' => $this
        ->t('1999 by month'),
      '#attributes' => [
        'id' => [
          'ninetynine',
        ],
      ],
    ],
    [
      '#type' => 'button',
      '#value' => $this
        ->t('Last week of 1999'),
      '#attributes' => [
        'id' => [
          'lastweekninetynine',
        ],
      ],
    ],
    [
      '#type' => 'button',
      '#value' => $this
        ->t('Dec. 31, 1999'),
      '#attributes' => [
        'id' => [
          'lastdayninetynine',
        ],
      ],
    ],
  ];
  $text[] = $this
    ->t('The timestamps must be specified as Javascript timestamps, as milliseconds since January 1, 1970 00:00. This is like Unix timestamps, but in milliseconds instead of seconds (remember to multiply with 1000!).');
  $text[] = $this
    ->t('As an extra caveat, the timestamps are interpreted according to UTC and, by default, displayed as such. You can set the axis "timezone" option to "browser" to display the timestamps in the user\'s timezone, or, if you use timezoneJS, you can specify a time zone.');
  $output['flot'] = [
    '#type' => 'flot',
    '#data' => $d,
    '#options' => $options,
    '#theme' => 'flot_examples',
    '#text' => $text,
    '#attached' => [
      'library' => [
        'flot_examples/axes_time',
      ],
    ],
  ];
  return $output;
}