PDA

View Full Version : QML ChartView updates



scgrant327
15th August 2016, 15:09
I am developing a smartphone app (Android & iOS). I have successfully implemented a Chartview and added a lineseries... no problems there...

However, I would like to update the lineseries on-the-fly... as in, I want to remove the first item and append a new item as data comes in (usually every 2 seconds or so).

Any ideas or thoughts on doing that? I've reviewed the docs, but don't readily see a way to handle this.
Thanks!

anda_skoa
15th August 2016, 18:48
It seems to have a removeSeries() method: http://doc.qt.io/qt-5/qml-qtcharts-chartview.html#removeSeries-method

Cheers,
_

scgrant327
15th August 2016, 19:10
Good Point.
I'll try using that with adding a new series and see how that will work, although there is no "addSeires"... Maybe 'createSeries' will work.

Will post back with an update...

scgrant327
9th September 2016, 15:38
Using removeSeries and createSeries works for Android.
For iOS, I get an error about AbstractSeries being undefined... same source code for both.

d_stranz
9th September 2016, 18:14
You probably don't have the include paths set up properly for iOS and it can't find the QML where AbstractSeries is defined.

scgrant327
13th September 2016, 15:33
QT and Xcode both compile this project without any issues...and run on my testbed iPhone. Everything works except the Qt Charts on iOS.

d_stranz
13th September 2016, 17:29
Compiling is probably not the issue. AFAIK, the QML is loaded at runtime, and your error implies that it can't find the base QML where AbstractSeries is defined. Look at how and where you are deploying the QML files and where your app is expecting them to be.

scgrant327
30th September 2016, 23:35
My code:

var wseries = windChart.createSeries(ChartView.SeriesTypeLine, "",axisXw, axisYw);

ios Error:

Error: Unknown method return type: QAbstractSeries*

Thoughts?

scgrant327
5th October 2016, 13:55
Anyone have any thoughts?

D_Stranz, can you elaborate on your idea? I've checked everything I can think of, and it appears to be OK... QT Creator and XCode both compile and seem to 'see' all libraries and headers ok...

d_stranz
5th October 2016, 17:15
I don't know what to tell you. When you build and run something under Qt Creator, you are running in a different environment than on the actual device (or in a test bed or on your desktop). Paths are different, the "current directory" is different, and so forth. "QAbstractSeries" is probably defined in a QML file associated with the Qt Charts package, and either you aren't deploying that file on iOS or you aren't deploying it in a search path that QML is using on iOS.

On my 5.4.1 distribution, "QAbstractSeries" is defined in the qabstractseries.h file down in the Charts source tree, and is referenced as a Component in the plugins.qmltypes file in the chartsqml2 directory.

Have you followed the instructions on Deploying QML Applications (http://doc.qt.io/qt-5/qtquick-deployment.html)?

scgrant327
7th October 2016, 14:11
Seems that the overall issue was running in Debug mode. Once I switched to a Release mode on iOS, the QAbstractSeries error went away... and the charts worked.

scgrant327
14th February 2017, 13:49
I know it's been a while, but I wanted to update this thread with how I ended up getting this to work best on iOS and Android...

I use the QML charts, and am dynamically updating them by doing a 'remove' followed by and 'append'. I have 4 charts, 3 of which have a single series, and one which has 2 series.

I define the each series at Chart creation, the populate the entire series with data from a MySQL DB... then as new data is added to the DB, I do this for each series ( as appropriate ):


series1.remove(0);
series1.append(incomingData.msec,incomingData.data Point);

This removes the first item from the series (the oldest), and appends the newest item as the last in the series... works like a charm.

I was originally destroying and recreating each series... which worked, but this way is cleaner and is less effort.

I would assume that since I can do this via QML, you could do it via C++.

--Sam

Qtino
22nd May 2017, 18:26
I know it's been a while, but I wanted to update this thread with how I ended up getting this to work best on iOS and Android...

I use the QML charts, and am dynamically updating them by doing a 'remove' followed by and 'append'. I have 4 charts, 3 of which have a single series, and one which has 2 series.

I define the each series at Chart creation, the populate the entire series with data from a MySQL DB... then as new data is added to the DB, I do this for each series ( as appropriate ):


series1.remove(0);
series1.append(incomingData.msec,incomingData.data Point);

This removes the first item from the series (the oldest), and appends the newest item as the last in the series... works like a charm.

I was originally destroying and recreating each series... which worked, but this way is cleaner and is less effort.

I would assume that since I can do this via QML, you could do it via C++.

--Sam

Thanks for this post. It was very helpful.
I did similar coding in QML, but has an event with new data coming in.
I append the data to the lineseries during the event, but the chart doesn't get updated.
I also tried remove then append and it doesn't update to the new data.
Was there something else you call to cause the chart to get repaint?

-Qtino

d_stranz
23rd May 2017, 00:04
I append the data to the lineseries during the event, but the chart doesn't get updated.
I also tried remove then append and it doesn't update to the new data.

Are you sure that the line series you are modifying in your slot is the same one you added to the chart, and not some temporary line series you are creating in the slot (which then gets destroyed immediately)?

Since you haven't showed any of your code, there's no way to tell what you might be doing wrong.