Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Implementing real time plot with Qt5 charts

Implementing real time plot with Qt5 charts

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 769 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.
  • SanchayanMaityS Offline
    SanchayanMaityS Offline
    SanchayanMaity
    wrote on last edited by
    #1

    Hello,

    I am new to Qt and trying to implement a real time plot using QSplineSeries with Qt 5.7. I need to scroll the x axis as new data comes in every 100ms. It seems the CPU usage reaches 100% if I do not purge the old data which was appended to the series, using graphSeriesX->remove(0). I found two ways of scrolling the x axis.

        const uint8_t X_RANGE_COUNT = 50;
        const uint8_t X_RANGE_MAX = X_RANGE_COUNT - 1;
        qreal y = (axisX->max() - axisX->min()) / axisX->tickCount();
        m_x += y;
        if (m_x > axisX->max()) {
            axisX->setMax(m_x);
            axisX->setMin(m_x - 100);
        }
    
        if (graphSeries1->count() > X_RANGE_COUNT) {
            graphSeries1->remove(0);
            graphSeries2->remove(0);
            graphSeries3->remove(0);
        }
    

    The problem with the above is that m_x is of type qreal and at some time if I keep the demo running continuously, it will reach it's MAX value and the axisX->setMax call will fail making the plot not work anymore. What would be the correct way to fix this use case?

    1. In the second method I use scroll as
    qreal x = plotArea().width() / X_RANGE_MAX;
    chart->scroll(x, 0)
     if (graphSeries1->count() > X_RANGE_COUNT) {
                graphSeries1->remove(0);
                graphSeries2->remove(0);
                graphSeries3->remove(0);
     }
    

    However it's not clear to me how can I use the graphSeriesX->remove(0) call in this scenario. The graph will keep getting wiped out since once the series get appended with X_RANGE_COUNT values, the if block will always be true removing 0th value but the scroll somehow does not work the way manually setting maximum for x axis works and after a while I have no graph. scroll works if I do not call remove but then my CPU usage reaches 100%.

    Can someone point me in the right direction?

    Regards,
    Sanchayan.

    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