Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to expose multiple X and Y data to QML for charts
Forum Updated to NodeBB v4.3 + New Features

How to expose multiple X and Y data to QML for charts

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 516 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Praveen.Illa
    wrote on last edited by Praveen.Illa
    #1

    Hi Team,
    I am new to Qt and am struggling to implement a below requirement. Can anyone in the group suggest me how to implement

    I 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

    eyllanescE 1 Reply Last reply
    0
    • GabrielRRG Offline
      GabrielRRG Offline
      GabrielRR
      wrote on last edited by
      #2

      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);
      

      Lic-Ing. Jose Gabriel Lopez Villalobos
      Embedded Software Engineer
      RidgeRun Engineering Ltd.
      www.ridgerun.com
      Email: gabriel.lopez@ridgerun.com

      1 Reply Last reply
      0
      • P Praveen.Illa

        Hi Team,
        I am new to Qt and am struggling to implement a below requirement. Can anyone in the group suggest me how to implement

        I 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

        eyllanescE Offline
        eyllanescE Offline
        eyllanesc
        wrote on last edited by
        #3

        @Praveen-Illa See this example: https://stackoverflow.com/questions/48687705/how-to-use-the-vxymodelmapper-with-qstandarditemmodel/48688921#48688921

        If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

        P 1 Reply Last reply
        0
        • eyllanescE eyllanesc

          @Praveen-Illa See this example: https://stackoverflow.com/questions/48687705/how-to-use-the-vxymodelmapper-with-qstandarditemmodel/48688921#48688921

          P Offline
          P Offline
          Praveen.Illa
          wrote on last edited by
          #4

          @eyllanesc - Thank you for your support. I am able to plot the graphs in QML

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved