Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QChart QLegend handle jitter due to rapid updates
Forum Updated to NodeBB v4.3 + New Features

QChart QLegend handle jitter due to rapid updates

Scheduled Pinned Locked Moved Solved General and Desktop
qchartqlegendqsizepolicy
6 Posts 4 Posters 1.5k Views 2 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.
  • A Offline
    A Offline
    Ambyjkl
    wrote on 20 Dec 2017, 21:22 last edited by
    #1

    Hi,
    I'm using QChart for plotting a graph, and I have a QLineSeries for each value I'm plotting. I constantly fetch the values from an arduino connected to a sensor and add the values to the chart. I'm setting the "name" of the line series to the latest value:

    currLine->setName(QString("%1").arg(newVal));
    

    so the legend updates every time to newVal. The problem I'm facing is that I get the values too rapidly, so there's a lot of jitter because the QLegend on the chart keeps resizing to the preferred value. I want the legend to only expand if the preferred size is more than the current size, so I tried setting the horizontal size policy to QSizePolicy::MinimumExpanding like so:

    chart->legend()->sizePolicy().setHorizontalPolicy(QSizePolicy::MinimumExpanding);
    

    but that doesn't do the trick unfortunately :(.

    Any help would be highly appreciated. If you need a demonstration, I have a short video clip that I tried uploading, but currently I "don't have enough permissions for it", considering this is my first forum post. If you need to see it, I can send it to you by email.

    Thanks a lot!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 20 Dec 2017, 21:25 last edited by
      #2

      Hi and welcome to devnet,

      Since the values are coming in to rapidly to be really useful, why not slow down the update of the name ? There's no use updating it a hundred time per second.

      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
      • A Offline
        A Offline
        Ambyjkl
        wrote on 20 Dec 2017, 22:07 last edited by
        #3

        Yeah, that would be one solution, and I might end up going with it if nothing else works out. My only concern is that the number and the chart would be out of sync and it would be misleading. But is there a way to achieve what I'm trying to do right now?

        M 6 2 Replies Last reply 20 Dec 2017, 23:12
        0
        • A Ambyjkl
          20 Dec 2017, 22:07

          Yeah, that would be one solution, and I might end up going with it if nothing else works out. My only concern is that the number and the chart would be out of sync and it would be misleading. But is there a way to achieve what I'm trying to do right now?

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 20 Dec 2017, 23:12 last edited by
          #4

          @Ambyjkl
          I dont know QChart very well but i was wondering if
          you detach the legends() and controlled the sizing if that would help ?
          https://doc.qt.io/qt-5.10/qtcharts-legend-example.html

          1 Reply Last reply
          0
          • A Ambyjkl
            20 Dec 2017, 22:07

            Yeah, that would be one solution, and I might end up going with it if nothing else works out. My only concern is that the number and the chart would be out of sync and it would be misleading. But is there a way to achieve what I'm trying to do right now?

            6 Offline
            6 Offline
            6thC
            wrote on 20 Dec 2017, 23:47 last edited by
            #5

            @Ambyjkl Short story: I implemented my own legend and hide the QtCharts legend for many reasons.

            I needed to maximize the chart area and wanted to position the legend as a completely disconnected object. That is powered by a ListModel, which has a QML var (I pass a name, series ref. and a real value placeholder). In as realtime as you can get - I can see the last series value drawn and as a number, change colors, series selections... it's very possible.

            I share the others' concerns you're updating too fast for no visible benefit - there's no reason to update so fast due to our eyes not seeing. If there's business logic needing action at high sample rates keep it in c++.

            There's other ways than blunt force, are you values frequently the same across those fast updates?
            I have the potential to do chart updates around 14ms (tested) but my data baud in the real world is nowhere near. Even so, I only signal to change on a value that actually does change.

            Identical values do not propogate in my application, an component initializing can do a one off value read, then bind to the property changed signals or just wait for the next update.

            I also predetermine the maximum legend and internal item sizes on loading and restrict text to the containers not let the content go nuts like that. I know the longest series names and the maximum values to be written so I know max char lengths, I know the legend component dimensions, the rest is layouts and text metrics fun.

            A 1 Reply Last reply 21 Dec 2017, 00:39
            0
            • 6 6thC
              20 Dec 2017, 23:47

              @Ambyjkl Short story: I implemented my own legend and hide the QtCharts legend for many reasons.

              I needed to maximize the chart area and wanted to position the legend as a completely disconnected object. That is powered by a ListModel, which has a QML var (I pass a name, series ref. and a real value placeholder). In as realtime as you can get - I can see the last series value drawn and as a number, change colors, series selections... it's very possible.

              I share the others' concerns you're updating too fast for no visible benefit - there's no reason to update so fast due to our eyes not seeing. If there's business logic needing action at high sample rates keep it in c++.

              There's other ways than blunt force, are you values frequently the same across those fast updates?
              I have the potential to do chart updates around 14ms (tested) but my data baud in the real world is nowhere near. Even so, I only signal to change on a value that actually does change.

              Identical values do not propogate in my application, an component initializing can do a one off value read, then bind to the property changed signals or just wait for the next update.

              I also predetermine the maximum legend and internal item sizes on loading and restrict text to the containers not let the content go nuts like that. I know the longest series names and the maximum values to be written so I know max char lengths, I know the legend component dimensions, the rest is layouts and text metrics fun.

              A Offline
              A Offline
              Ambyjkl
              wrote on 21 Dec 2017, 00:39 last edited by
              #6

              @6thC cool story, thanks for the detailed reply! I've realized that QLegend isn't the best solution for me, so I ended up doing something similar to what you did. I'm using labels with a monospaced font and splitting the whole and fractional parts, so it's a lot nicer now

              1 Reply Last reply
              0

              1/6

              20 Dec 2017, 21:22

              • Login

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