private function SeriesToggle::getData in Flot 8
Fetch the data from the raw text file.
File
- flot_examples/
src/ Controller/ SeriesToggle.php, line 46
Class
- SeriesToggle
- Display a chart demonstrating hiding series.
Namespace
Drupal\flot_examples\ControllerCode
private function getData() {
$file_path = DRUPAL_ROOT . '/' . drupal_get_path('module', 'flot_examples') . '/src/Controller/MilitaryData.txt';
$file = fopen($file_path, "r") or die("Unable to open file: {$file_path}");
$countries = [
'usa',
'russia',
'uk',
'germany',
'denmark',
'sweden',
'norway',
];
$data = [];
while (!feof($file)) {
$line = fgets($file);
$values = explode(', ', $line);
if (count($values) > 1) {
$year = $values[0];
foreach ($countries as $key => $country) {
if ($values[$key + 1] != "") {
$data[$country]['data'][] = [
$year,
$values[$key + 1],
];
}
}
}
}
fclose($file);
return $data;
}