1212#include < QTextStream>
1313#include " jkqtplotter/jkqtplotter.h"
1414#include " jkqtplotter/graphs/jkqtpscatter.h"
15- #include " jkqtplotter/graphs/jkqtpgeometric.h"
1615#include " jkqtplotter/jkqtptools.h"
1716#include " jkqtplotter/graphs/jkqtpfilledcurve.h"
1817
@@ -29,18 +28,19 @@ void drawWithDateAxis(JKQTPlotter& plot) {
2928 // the second to fourth columns contain a floating-point number
3029 // with temperature average, min and max
3130 QFile file (" :/weatherdata_gelsenkirchen.csv" );
32- file.open (QFile::ReadOnly|QFile::Text);
33- file.readLine (); // eat comment
34- while (!file.atEnd ()) {
35- QString line=file.readLine ();
36- QTextStream in (&line);
37- QStringList items=line.split (" ;" );
38- // date/time values are stored as doubles representing the corresponding number of milliseconds sind epoch
39- date<<QDateTime::fromString (items[0 ], Qt::ISODate).toUTC ().toMSecsSinceEpoch ();
40- // store Heidelbergs daily temperature
41- temperature<<items[1 ].toDouble ();
42- temperature_min<<items[2 ].toDouble ();
43- temperature_max<<items[3 ].toDouble ();
31+ if (file.open (QFile::ReadOnly|QFile::Text)) {
32+ file.readLine (); // eat comment
33+ while (!file.atEnd ()) {
34+ QString line=file.readLine ();
35+ QTextStream in (&line);
36+ QStringList items=line.split (" ;" );
37+ // date/time values are stored as doubles representing the corresponding number of milliseconds sind epoch
38+ date<<QDateTime::fromString (items[0 ], Qt::ISODate).toUTC ().toMSecsSinceEpoch ();
39+ // store Heidelbergs daily temperature
40+ temperature<<items[1 ].toDouble ();
41+ temperature_min<<items[2 ].toDouble ();
42+ temperature_max<<items[3 ].toDouble ();
43+ }
4444 }
4545
4646 // 3. add a plot for the data mean line (graphTemperature) and range (graphTemperatureRange)
@@ -110,18 +110,19 @@ void drawWithTimeAxis(JKQTPlotter& plot) {
110110 // semicolon separated data. The first column is a time
111111 // the second contain a floating-point number with temperatures
112112 QFile file (" :/weatherdata_heidelberg_2018-10-14.csv" );
113- file.open (QFile::ReadOnly|QFile::Text);
114- file.readLine (); // eat comment
115- while (!file.atEnd ()) {
116- QString line=file.readLine ();
117- QTextStream in (&line);
118- QStringList items=line.split (" ;" );
119- // date/time values are stored as doubles representing the corresponding
120- // number of milliseconds sind epoch. Since the data is time only, we have to use an arbitrary
121- // date as basis
122- time<<QDateTime::fromString (" 1970-01-01T" +items[0 ], Qt::ISODate).toMSecsSinceEpoch ();
123- // store Heidelbergs daily temperature
124- temperature<<items[1 ].toDouble ();
113+ if (file.open (QFile::ReadOnly|QFile::Text)) {
114+ file.readLine (); // eat comment
115+ while (!file.atEnd ()) {
116+ QString line=file.readLine ();
117+ QTextStream in (&line);
118+ QStringList items=line.split (" ;" );
119+ // date/time values are stored as doubles representing the corresponding
120+ // number of milliseconds sind epoch. Since the data is time only, we have to use an arbitrary
121+ // date as basis
122+ time<<QDateTime::fromString (" 1970-01-01T" +items[0 ], Qt::ISODate).toMSecsSinceEpoch ();
123+ // store Heidelbergs daily temperature
124+ temperature<<items[1 ].toDouble ();
125+ }
125126 }
126127
127128 // 3. add a plot for the data mean line (graphTemperature) and range (graphTemperatureRange)
0 commit comments