QCustomPlot Discussion and Comments

Plotting Real Time Data or at least making the Real Time Plot Demo workReturn to overview

Hello,

I am not very new at programming, but I never tried to get deeper knowledge about anything in any programming language I learned than the basics. I can't really understand how to get the real time plot demo to work. I tried to copy the upper code and use it for my promoted widget. But I really don't have any clue about what to do with the "realtimeDataSlot()". And the example plots don't work, the compiler keeps throwing errors about makefile's header targets .

Insert this in to your code.
QTimer *dataTimer = new QTimer(this);

and create this function.
void MainWindow::realtimeDataSlot()
{
static QTime time(QTime::currentTime());
// calculate two new data points:
double key = time.elapsed()/1000.0; // time elapsed since start of demo, in seconds

// QVector<double> x(101); // initialize with entries 0..100
// for (int i=0; i<101; ++i)
// {
// //x = data1 ;// x goes from -1 to 1
// //y = x*x; // let's plot a quadratic function
// }

static double lastPointKey = 0;
if (key-lastPointKey > 0.002) // at most add point every 2 ms
{
// add data to lines:
ui->plot->graph(0)->addData(key, qSin(key)+qrand()/(double)RAND_MAX*1*qSin(key/0.3843));
//ui->plot->graph(0)->setData(key,(**data1));
//ui->plot->graph(1)->addData(key, qCos(key)+qrand()/(double)RAND_MAX*0.5*qSin(key/0.4364));
// rescale value (vertical) axis to fit the current data:
//ui->customPlot->graph(0)->rescaleValueAxis();
//ui->customPlot->graph(1)->rescaleValueAxis(true);
lastPointKey = key;
}
// make key axis range scroll with the data (at a constant range size of 8):
ui->plot->xAxis->setRange(key, 8, Qt::AlignRight);
ui->plot->replot();

// calculate frames per second:
static double lastFpsKey;
static int frameCount;
++frameCount;
if (key-lastFpsKey > 2) // average fps over 2 seconds
{
ui->statusBar->showMessage(
QString("%1 FPS, Total Data points: %2")
.arg(frameCount/(key-lastFpsKey), 0, 'f', 0)
.arg(ui->plot->graph(0)->data()->size()+ui->plot->graph(1)->data()->size())
, 0);
lastFpsKey = key;
frameCount = 0;
}

[code][QSharedPointer<QCPAxisTickerTime> timeTicker(new QCPAxisTickerTime);
timeTicker->setTimeFormat("%h:%m:%s");
ui->customPlot->xAxis->setTicker(timeTicker);
ui->customPlot->axisRect()->setupFullAxesBox();
ui->customPlot->yAxis->setRange(0,300);
ui->customPlot->xAxis->setLabel("time\n\n\n");
ui->customPlot->graph()->setPen(QPen(QColor(40,110,255)));

Hi.,
I am trying this program to plot the time on x axis but i am not getting correct time.
I don't need real time data.Ie I am getting 00:05:00,00:10:00 In place of seconds i am getting 00 and in place of minute i am getting 05 ,10,15 like that .plz help me to resolve the problem