QCustomPlot Discussion and Comments

QTcpsockets to graphsReturn to overview

Hello geeks,i am analyzing packets and pumping them to QTableWidget ,but now problem is i want them to pump them on graphs dynamically please give me some hint guys i am facing problem.please

Hi shekar,
The basic plotting tutorial and the realtime demo (one of the plot examples in the full download package) will surely help you.

Hi,

To have your graph evolving dynamically, you can do something like that.

//your new incomming data
double newXData, newYData;

//Update the display range of your graph
double xDiff, yDiff;
xDiff = newXData - yourGraph->xAxis->range()->upper();
yDiff = newYData- yourGraph->yAxis->range()->upper();

if( xDiff > 0.) {
    yourGraph->xAxis->setRange(yourGraph->xAxis->range()->upper() + xDiff);
}
if( yDiff> 0.) {
    yourGraph->yAxis->setRange(yourGraph->yAxis->range()->upper() + yDiff);
}

// I guess you should put these data into a QVector<double>, I do not remember.
yourGraph->addData(newXData, newYData);

So basically you:
_ update the display range of your graph since your data may be off bounds (for example, if your time is on the xAxis)
_ add your incomming data to the new graph.

Thank u all..
Now i am able to build static graph , but can i build it every 0.5 second interval like animation graphs....(Example:CPU usage graph in windows).

Yes, my first post on 28. July mentions the realtime demo in the examples project. This demonstrates what you need, an animated graph that gets data added on the right.

Thanks
But i want to plot a data which is coming by qtcpsocket, packets are coming at 0.5 second when i press start button the graph starts playing (before to graph project i was able to put data on table widget dynamically)but how to update to graph i am not getting..can u paste some example please...

Well to me it sounds like exactly what the realtime demo shows you how to do. If this is not the case, please say in which exact step you're having difficulties.

I am modifying the interaction example i qcustomplot examples set i am facing problem here

int n =50 ;
double xScale = (rand()/(double)RAND_MAX + 0.5)*1;
double yScale = (rand()/(double)RAND_MAX + 0.5)*1;
double xOffset = (rand()/(double)RAND_MAX + 0.5)*2;
double yOffset = (rand()/(double)RAND_MAX + 0.5)*2;
double r1 = (rand()/(double)RAND_MAX + 0.5)*2;
double r2 = (rand()/(double)RAND_MAX + 0.5)*2;

QVector<double> x(n), y(n);
for (int i=0; i<n; i++)
{
x = (i/(double)n-0.5)*10.0*xScale + xOffset;
y = (sin(x*r1*5)*sin(cos(x*r2)*3)+r1*cos(sin(x)*r2*2))*yScale + yOffset;
}
now i am storing values in
QTcpSocket sock;
sock.connectToHost("188.68.---",2500);
QObject::connect(&sock, SIGNAL(readyRead()), this, SLOT(read()));
}

Now from sock variable i want to print in graph randomly but looks like animated moving zigzag....

Hi shekhar, please post your read() slot as well.

Friends i am not able to see realtime demo example in download package
list of examples in package are:
examples folder:
1.interactions.
2.plots.
3.scrollbar-axis-range-control.
4.text-document-integration.

can anyone provide me link.please i am having same requirement as shekhar
is having....

Thanks friends for all support i am able to print dynamic values...Thanks

@Karun patel:
The realtime demo is one of the plot examples. Open the project in the "plots" directory and find the MainWindow::setupRealtimeDataDemo function, and in this case also the MainWindow::realtimeDataSlot. That slot is called periodically with a timer to update data values and replot the graphs.