You are here

private function Percentiles::readData in Flot 8

Fetch the raw data from the data file.

File

flot_examples/src/Controller/Percentiles.php, line 166

Class

Percentiles
Displays a chart that demonstrates the fillbetween plugin.

Namespace

Drupal\flot_examples\Controller

Code

private function readData($filename) {
  $file_path = DRUPAL_ROOT . '/' . drupal_get_path('module', 'flot_examples') . '/src/Controller/' . $filename;
  $file = fopen($file_path, "r") or die("Unable to open file: {$file_path}");
  $stats = [
    "10%",
    "15%",
    "25%",
    "50%",
    "75%",
    "85%",
    "90%",
    "mean",
  ];
  $data = [];
  while (!feof($file)) {
    $line = fgets($file);
    $values = explode(', ', $line);
    if (count($values) > 1) {
      foreach ($stats as $key => $stat) {
        $data[$stat][] = [
          $values[0],
          $values[$key + 1],
        ];
      }
    }
  }
  fclose($file);
  return $data;
}