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. Get QtGraphs with XYModelMapper working
Qt 6.11 is out! See what's new in the release blog

Get QtGraphs with XYModelMapper working

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
15 Posts 5 Posters 1.1k Views 1 Watching
  • 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.
  • GrecKoG GrecKo

    You need to set the series property of your XYModelMapper.

    I Offline
    I Offline
    Igor23
    wrote last edited by
    #3

    @GrecKo Thanks! I also found that out. But the lineseries must also have a color different from backround and there must be explicit axes. My working qml file is now:

    import QtQuick
    import QtGraphs
    import graphsexample 1.0
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
        GraphsView {
            id: graphsView
            antialiasing: true
            anchors.fill: parent
            //legend.visible: false
            ValueAxis {
                id: axisX
                min: 0
                max: 10  // Anpassen an Ihre Daten
                titleText: "X-Achse"
            }
    
            ValueAxis {
                id: axisY
                min: 0
                max: 10  // Anpassen an Ihre Daten
                titleText: "Y-Achse"
            }
            LineSeries {
                id: lineSeries
                color: "#00ff00"
                joinStyle: Qt.RoundJoin
                XYModelMapper {
                    model: Graphsmodel
                    series: lineSeries
                    xSection: 0
                    ySection: 1
                }
                axisX: axisX
                axisY: axisY
            }
        }
    }
    

    Also this Connections don't work. It must be Graphsmodel with captal letter in XYModelMapper:

        Connections{
            id: graphsmodel
            target: Graphsmodel
        }
    
    1 Reply Last reply
    0
    • GrecKoG GrecKo

      You need to set the series property of your XYModelMapper.

      I Offline
      I Offline
      Igor23
      wrote last edited by
      #4

      @GrecKo I have an additional question, because it is important for my project:
      How can I update the axes in the following sense:

      ValueAxis {
          id: axisX
          min: Graphsmodel.returnXmin()
          max: Graphsmodel.returnXmax()
          titleText: "X-Achse"
      }
      

      Even with fixed starting values this is not working for me.

      1 Reply Last reply
      0
      • GrecKoG Offline
        GrecKoG Offline
        GrecKo
        Qt Champions 2018
        wrote last edited by
        #5

        Try to expose the xMin and xMan as properties with a NOTIFY signal instead to make the min and max binding automatically update. I guess it is currently calling returnXmin/max initially when the model is maybe empty, and then it isn't called again.

        I 1 Reply Last reply
        1
        • GrecKoG GrecKo

          Try to expose the xMin and xMan as properties with a NOTIFY signal instead to make the min and max binding automatically update. I guess it is currently calling returnXmin/max initially when the model is maybe empty, and then it isn't called again.

          I Offline
          I Offline
          Igor23
          wrote last edited by Igor23
          #6

          @GrecKo How do you mean this exactly? Can you give an example code?

          JoeCFDJ 1 Reply Last reply
          0
          • I Offline
            I Offline
            Igor23
            wrote last edited by Igor23
            #7

            And I have a second additional question: is there maximum number of points I can draw via Lineseries and XYModelMapper? It seems to me as there is a limit by Qt framework ...

            JoeCFDJ 1 Reply Last reply
            0
            • I Igor23

              @GrecKo How do you mean this exactly? Can you give an example code?

              JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote last edited by JoeCFD
              #8

              @Igor23 add the following in your model
              Q_PROPERTY( float minX MEMBER m_fMinX NOTIFY minXChanged )
              define m_fMinX and signal minXChanged in your model.

              Do the same for maxX.

              and

              ValueAxis {
                  id: axisX
                  min: Graphsmodel.minX
                  max: Graphsmodel.maxX
                  titleText: "X-Achse"
              }
              
              
              I 1 Reply Last reply
              0
              • I Igor23

                And I have a second additional question: is there maximum number of points I can draw via Lineseries and XYModelMapper? It seems to me as there is a limit by Qt framework ...

                JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote last edited by
                #9

                @Igor23 It seems there is no limit. But your drawing will get slower if there are too many points. You need some kind of optimization.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote last edited by
                  #10

                  The LineSeries type has a count property that returns the number of data points in the series so I would venture that the maximum int value is the limit but I wouldn't try to show that many data point anyway because it does not make sense. If anything, I would rather allow the user to zoom in/out of sections of a LineSeries if they need more precise data.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • JoeCFDJ JoeCFD

                    @Igor23 add the following in your model
                    Q_PROPERTY( float minX MEMBER m_fMinX NOTIFY minXChanged )
                    define m_fMinX and signal minXChanged in your model.

                    Do the same for maxX.

                    and

                    ValueAxis {
                        id: axisX
                        min: Graphsmodel.minX
                        max: Graphsmodel.maxX
                        titleText: "X-Achse"
                    }
                    
                    
                    I Offline
                    I Offline
                    Igor23
                    wrote last edited by
                    #11

                    @JoeCFD This works for me. Thank you!

                    1 Reply Last reply
                    0
                    • I Igor23 has marked this topic as solved
                    • I Igor23 has marked this topic as unsolved
                    • I Offline
                      I Offline
                      Igor23
                      wrote last edited by
                      #12

                      Sorry, I still have a question: How can I make a logarithmic scale to one axis? I didn't find in the web - only for 3D.

                      JoeCFDJ 1 Reply Last reply
                      0
                      • I Igor23

                        Sorry, I still have a question: How can I make a logarithmic scale to one axis? I didn't find in the web - only for 3D.

                        JoeCFDJ Offline
                        JoeCFDJ Offline
                        JoeCFD
                        wrote last edited by
                        #13
                        This post is deleted!
                        B 1 Reply Last reply
                        0
                        • JoeCFDJ JoeCFD

                          This post is deleted!

                          B Offline
                          B Offline
                          Bob64
                          wrote last edited by
                          #14

                          @JoeCFD That is Charts - I believe @Igor23 is using the newer Graphs module. From what I remember when I looked into it, logarithmic axis was one of the missing features of Graphs vs Charts.

                          JoeCFDJ 1 Reply Last reply
                          2
                          • B Bob64

                            @JoeCFD That is Charts - I believe @Igor23 is using the newer Graphs module. From what I remember when I looked into it, logarithmic axis was one of the missing features of Graphs vs Charts.

                            JoeCFDJ Offline
                            JoeCFDJ Offline
                            JoeCFD
                            wrote last edited by
                            #15

                            @Bob64 You are right. I did not pay attention to it.

                            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