Read data and add it to a chart
-
@jsulm I don't want it to read all the data and add it to the chart. It can read the entire file in once, but I want it to add the data to the chart every 0.2 seconds. It should always proceed by adding the most recently read data to the chart
@suslucoder said in Read data and add it to a chart:
but I want it to add the data to the chart every 0.2 seconds
Then this is not "realtime".
You already have the file content in allLines and you already have Timer_Slot() slot. So, what prevents you from adding next data line to your chart in that slot? -
@suslucoder said in Read data and add it to a chart:
but I want it to add the data to the chart every 0.2 seconds
Then this is not "realtime".
You already have the file content in allLines and you already have Timer_Slot() slot. So, what prevents you from adding next data line to your chart in that slot?wrote on 4 Jan 2021, 08:18 last edited by@jsulm I dont know how to do it, that is the reason I asked for help
-
@jsulm I dont know how to do it, that is the reason I asked for help
@suslucoder There are many examples: https://doc.qt.io/qt-5/qtcharts-examples.html
Take time to see how data is added to a chart. -
@suslucoder There are many examples: https://doc.qt.io/qt-5/qtcharts-examples.html
Take time to see how data is added to a chart.wrote on 4 Jan 2021, 08:30 last edited by@jsulm as you said, I already have the file content in allLines. When i do series.append(allLines) to adding chart I get an error. Thank you I will analyze the examples
-
@jsulm as you said, I already have the file content in allLines. When i do series.append(allLines) to adding chart I get an error. Thank you I will analyze the examples
@suslucoder I told you in that other thread from you that you can't use a string list there. Please also read documentation...
-
@jsulm as you said, I already have the file content in allLines. When i do series.append(allLines) to adding chart I get an error. Thank you I will analyze the examples
wrote on 4 Jan 2021, 08:36 last edited by@suslucoder
@jsulm already answered this last question in https://forum.qt.io/topic/122320/how-can-i-add-txt-file-datas-in-qlineseries/2. You cannot add a a string (or string list) to a chart, you have to parse it to generate the actual desired numbers.For adding data every few seconds: whether you read the lines from the file as you go or you read them all into a list in memory, either way on a
QTimer::timeout()
signal read the next however-many from the file/list and add them to the chart. -
@suslucoder
@jsulm already answered this last question in https://forum.qt.io/topic/122320/how-can-i-add-txt-file-datas-in-qlineseries/2. You cannot add a a string (or string list) to a chart, you have to parse it to generate the actual desired numbers.For adding data every few seconds: whether you read the lines from the file as you go or you read them all into a list in memory, either way on a
QTimer::timeout()
signal read the next however-many from the file/list and add them to the chart.wrote on 4 Jan 2021, 08:45 last edited by@JonB Okey. I understand. I should use another struct instead of string list, right?
-
@JonB Okey. I understand. I should use another struct instead of string list, right?
wrote on 4 Jan 2021, 08:49 last edited by@suslucoder
Well it's not another "struct". You presumably have a file containing the text of numbers, perhaps separated by commas or new lines or something. You need to convert those to X,Y numeric values, and then pass those (orQPointF
s) to add to the chart series. It doesn't matter whether you do that at the time of reading in the file or just before adding them to the series, but you will need to do so at one of those two stages. -
@JonB Okey. I understand. I should use another struct instead of string list, right?
@suslucoder said in Read data and add it to a chart:
I should use another struct instead of string list, right?
You should use what the method to set the data expects. That's why I suggested to read the documentation: it is documented quite clearly.
-
@suslucoder said in Read data and add it to a chart:
I should use another struct instead of string list, right?
You should use what the method to set the data expects. That's why I suggested to read the documentation: it is documented quite clearly.
wrote on 4 Jan 2021, 09:17 last edited by@jsulm ıs there any example that doing exactly what you said?
-
@jsulm ıs there any example that doing exactly what you said?
Lifetime Qt Championwrote on 4 Jan 2021, 09:19 last edited by jsulm 1 Apr 2021, 09:21@suslucoder I already posted a link to charts examples.
For example: https://doc.qt.io/qt-5/qtcharts-temperaturerecords-example.html
And you still did not tell us what data you actually want to show and what type of chart you need... -
Hi
Please show one line from the "C:/Users/ilknu/Documents/QFileDemo/abc.txt"
so we know how data is. else it's impossible to give any hints on how you can show that in a chart. -
Hi
Please show one line from the "C:/Users/ilknu/Documents/QFileDemo/abc.txt"
so we know how data is. else it's impossible to give any hints on how you can show that in a chart.wrote on 4 Jan 2021, 10:39 last edited by@mrjj Here it is
1991 01 213.5 136.9 0.64 220.5 147.6 229.4 205.5 8 17.4
1991 02 270.2 167.5 0.62 221.5 147.6 243.0 206.3 10 18.4 -
@mrjj Here it is
1991 01 213.5 136.9 0.64 220.5 147.6 229.4 205.5 8 17.4
1991 02 270.2 167.5 0.62 221.5 147.6 243.0 206.3 10 18.4wrote on 4 Jan 2021, 10:49 last edited by JonB 1 Apr 2021, 10:53QString line = read_one_line_from_file(); QStringList list = line.split(QLatin1Char(' '), Qt::SkipEmptyParts); for (const QString &entry : list) { double num = entry.toDouble(); // or `unsigned num = entry.toUInt()` for the first 2 numbers on each line, by the look of it // do whatever is necessary with each `double` number retrieved // such as adding pairs directly to the chart, or building a `QLineSeries`, or whatever }
-
QString line = read_one_line_from_file(); QStringList list = line.split(QLatin1Char(' '), Qt::SkipEmptyParts); for (const QString &entry : list) { double num = entry.toDouble(); // or `unsigned num = entry.toUInt()` for the first 2 numbers on each line, by the look of it // do whatever is necessary with each `double` number retrieved // such as adding pairs directly to the chart, or building a `QLineSeries`, or whatever }
wrote on 4 Jan 2021, 11:03 last edited by@JonB Thank you. Where should I place the code script?
-
@JonB Thank you. Where should I place the code script?
@suslucoder said in Read data and add it to a chart:
Where should I place the code script?
Come on. Place is where you read the data from the file...
-
@suslucoder said in Read data and add it to a chart:
Where should I place the code script?
Come on. Place is where you read the data from the file...
wrote on 4 Jan 2021, 12:12 last edited by@jsulm I know but i have, QString line = in.readLine();
allLines.append(line);
I couldnt get the idea about it. When i do it i get out of index error .And after doing all this things, how can i add my datas to a chart? -
@jsulm I know but i have, QString line = in.readLine();
allLines.append(line);
I couldnt get the idea about it. When i do it i get out of index error .And after doing all this things, how can i add my datas to a chart?wrote on 4 Jan 2021, 12:26 last edited by@suslucoder I did this part. After that, how can i add it to a chart? Like the way create a new chart, append series and it goes like this?
-
@jsulm I know but i have, QString line = in.readLine();
allLines.append(line);
I couldnt get the idea about it. When i do it i get out of index error .And after doing all this things, how can i add my datas to a chart?@suslucoder said in Read data and add it to a chart:
And after doing all this things, how can i add my datas to a chart?
I already provided links to examples several times.
"When i do it i get out of index error" - then post your code...
-
@suslucoder said in Read data and add it to a chart:
And after doing all this things, how can i add my datas to a chart?
I already provided links to examples several times.
"When i do it i get out of index error" - then post your code...
wrote on 4 Jan 2021, 12:58 last edited by@jsulm ```
QString line = in.readLine();
allLines.append(line);
QStringList list = line.split(QLatin1Char(' '), Qt::SkipEmptyParts);
for(const QString &entry : list) {
double num = entry.toDouble();
}
series->append(num)
``
Says use of undeclared identifier num
15/28