private function Selection::readData in Flot 8
Fetch the raw data from the data file.
File
- flot_examples/
src/ Controller/ Selection.php, line 69
Class
- Selection
- Display a chart that demonstrates region selection and zooming.
Namespace
Drupal\flot_examples\ControllerCode
private function readData() {
$filename = "CO2CountryData.txt";
$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}");
$countries = [
$this
->t("United States"),
$this
->t("Russia"),
$this
->t("United Kingdom"),
$this
->t("Germany"),
$this
->t("Denmark"),
$this
->t("Sweden"),
$this
->t("Norway"),
];
$data = [];
foreach ($countries as $key => $country) {
$data[$key]['label'] = $country;
}
while (!feof($file)) {
$line = fgets($file);
$values = explode(', ', $line);
if (count($values) > 1) {
foreach ($countries as $key => $country) {
if ($values[$key + 1] != "") {
$data[$key]['data'][] = [
$values[0],
$values[$key + 1],
];
}
}
}
}
fclose($file);
return $data;
}