<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QtCustomPlot Realtime Data Demo]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I'm new to this Qt and I am trying to plot a real time data graph with random data via QtCustomPlot.  The graph that I generated was unable to show the real time random data. May I know what is the problem of my code?<br />
Below is the source code:</p>
<p dir="auto">void MainWindow::setupRealtimeDataDemo(QCustomPlot *customPlot)<br />
{<br />
customPlot-&gt;addGraph(); // blue line<br />
customPlot-&gt;graph(0)-&gt;setPen(QPen(Qt::blue));<br />
customPlot-&gt;graph(0)-&gt;setBrush(QBrush(QColor(240, 255, 200)));<br />
customPlot-&gt;graph(0)-&gt;setAntialiasedFill(false);</p>
<p dir="auto">customPlot-&gt;addGraph(); // blue dot<br />
customPlot-&gt;graph(1)-&gt;setPen(QPen(Qt::blue));<br />
customPlot-&gt;graph(1)-&gt;setLineStyle(QCPGraph::lsNone);<br />
customPlot-&gt;graph(1)-&gt;setScatterStyle(QCPScatterStyle::ssDisc);</p>
<p dir="auto">QSharedPointer&lt;QCPAxisTickerTime&gt; timeTicker(new QCPAxisTickerTime);<br />
timeTicker-&gt;setTimeFormat("%h:%m:%s");<br />
customPlot-&gt;xAxis-&gt;setTicker(timeTicker);<br />
customPlot-&gt;axisRect()-&gt;setupFullAxesBox();<br />
customPlot-&gt;yAxis-&gt;setRange(-40, 40);</p>
<p dir="auto">connect(customPlot-&gt;xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot-&gt;xAxis2, SLOT(setRange(QCPRange)));<br />
connect(customPlot-&gt;yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot-&gt;yAxis2, SLOT(setRange(QCPRange)));</p>
<p dir="auto">connect(&amp;dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));<br />
dataTimer.start(0);<br />
}</p>
<p dir="auto">void MainWindow::realtimeDataSlot()<br />
{</p>
<pre><code>std::uniform_real_distribution&lt;double&gt;distribution(1,20.5);
    double value1 = distribution(*QRandomGenerator::global());
    qDebug() &lt;&lt; value1;
    while(value1 !=0)
    {
        value1=distribution(*QRandomGenerator::global());
        qDebug() &lt;&lt; value1;

    }


static QTime time(QTime::currentTime());
double key = time.elapsed()/1000.0; 
static double lastPointKey = 0;
if (key-lastPointKey &gt; 0.002) // at most add point every 2 ms
{
  ui-&gt;customPlot-&gt;graph(0)-&gt;addData(key, value1);
  ui-&gt;customPlot-&gt;graph(1)-&gt;addData(key, value1);
  lastPointKey = key;
}
ui-&gt;customPlot-&gt;xAxis-&gt;setRange(key, 8, Qt::AlignRight);
ui-&gt;customPlot-&gt;replot();
</code></pre>
<p dir="auto">}</p>
]]></description><link>https://forum.qt.io/topic/126676/qtcustomplot-realtime-data-demo</link><generator>RSS for Node</generator><lastBuildDate>Thu, 30 Apr 2026 19:39:03 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/126676.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 15 May 2021 08:53:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QtCustomPlot Realtime Data Demo on Sun, 16 May 2021 16:21:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
Hi, its totally plot nth once I start running it.</p>
]]></description><link>https://forum.qt.io/post/659938</link><guid isPermaLink="true">https://forum.qt.io/post/659938</guid><dc:creator><![CDATA[Jayden123]]></dc:creator><pubDate>Sun, 16 May 2021 16:21:09 GMT</pubDate></item><item><title><![CDATA[Reply to QtCustomPlot Realtime Data Demo on Sat, 15 May 2021 09:00:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jayden123">@<bdi>Jayden123</bdi></a> said in <a href="/post/659779">QtCustomPlot Realtime Data Demo</a>:</p>
<blockquote>
<p dir="auto">The graph that I generated was unable to show the real time random data.</p>
</blockquote>
<p dir="auto">What exactly happens?  It plots nothing?  It plots the wrong things?  It plots the right things, but not all of them?  It works for a while and then goes wrong?  The re-range-scaling does not work right?  Or what?</p>
<p dir="auto">Although it may not be your problem, I would recommend you get rid of your <code>static</code> variables and make them members of <code>MainWindow</code>, and initialize them as appropriate.</p>
]]></description><link>https://forum.qt.io/post/659781</link><guid isPermaLink="true">https://forum.qt.io/post/659781</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 15 May 2021 09:00:11 GMT</pubDate></item></channel></rss>