How to expose multiple X and Y data to QML for charts
-
Hi Team,
I am new to Qt and am struggling to implement a below requirement. Can anyone in the group suggest me how to implementI have a requirement of plotting a graph in QML. For this, I need to send the list of X and Y- data from Qt -C++ (via list or QMap) to QML for plotting.
The X-axis is unsigned long int and Y-axis is double.
How can I send the list data in the format (X, Y), to the QML.
Also, i have seen in some of the forums suggesting to use QVariantList or QVariantMap. But, am not sure how to use these data types -
Hello, maybe something like this should help you using QMap
C++ type that maybe could help you:class myCustomMap: public QObject { Q_OBJECT public : myCustomMap(); Q_INVOKABLE int getX(int x) const { return _myMap.contains(x) ? _someMap[x] : 0; } private: const static QMap<int, int> _myMap; // Map``` }
I think with this you got the idea on how to proceed, you just need to create your QMap to accept something like:
struct Data{ int x = 0; int y = 0; }; QMultiMap<int, Data> map; Data data; data.x = 1; data.y = 2; map.insert(1, data);
-
-
@eyllanesc - Thank you for your support. I am able to plot the graphs in QML