Problem in Real Time data plotting



  • hai,,,,

    I have tested code for plotting the data with some inner loop in code as shown below

    @float y[20];
    float x[20];
    int i;
    for(i=0;i<20;i++)
    {
    x[i]=i;
    y[i]=2*sin((x[i]));
    }
    QwtPlot *plot=new QwtPlot();
    plot->setTitle( "Plot Demo" );
    plot->setCanvasBackground( Qt::white );
    //plot->setAxisScale( QwtPlot::yLeft, 0.0, 20.0);
    // plot->setAxisScale(QwtPlot::xBottom, 0.0, 20.0);
    plot->insertLegend( new QwtLegend() );
    plot->setAxisTitle(QwtPlot::xBottom, "X Axis");
    plot->setAxisTitle(QwtPlot::yLeft, "Y Axis");
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->attach( plot );
    QwtPlotCurve *curve = new QwtPlotCurve();
    curve->setTitle( "Pixel Count" );
    curve->setPen(QPen(Qt::blue, 3) ),
    curve->setRenderHint( QwtPlotItem::RenderAntialiased, true);
    QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,QBrush(Qt::yellow),QPen(Qt::red,2),QSize(8,8));
    curve->setSymbol(symbol );

    QPolygonF points;
    for(i=0;i<20;i++)
        points<<QPointF(x[i],y[i]);
     curve->setSamples( points );
    curve->attach(plot );
    plot->resize( 600, 400 );
    plot->show();@
    

    Its working fine.

    now I want to plot the data which is reading from standardoutput.....this code is as below

    @
    QByteArray b1;
    QList<QByteArray> read_data;
    b1= process->readAllStandardOutput();
    read_data=b1.split('\n');
    int i=0,n=read_data.count();
    float y[100000];
    for(i=0;i<n;i++)
    {
    QString result=read_data.at(i);
    result.remove(0,10);
    y[i]=result.toLatin1().toFloat();
    }
    @

    NOTE: running process is infinite loop. that is not problem because it is also working fine.

    but while combining both, its compiled but the output window for plotting is opened multiple times.how can plot using both these codes means how can comined the code.

    I tried like this

    @
    QByteArray b1;
    QList<QByteArray> read_data;
    b1= process->readAllStandardOutput();
    read_data=b1.split('\n');
    int i=0,n=read_data.count();
    float y[100000],x[100000];
    for(i=0;i<100000;i++)
    x[i]=i+1;
    QPolygonF points;
    QwtPlot *plot=new QwtPlot();
    plot->setTitle( "Plot Demo" );
    plot->setCanvasBackground( Qt::white );
    //plot->setAxisScale( QwtPlot::yLeft, 0.0, 20.0);
    // plot->setAxisScale(QwtPlot::xBottom, 0.0, 20.0);
    plot->insertLegend( new QwtLegend() );
    plot->setAxisTitle(QwtPlot::xBottom, "X Axis");
    plot->setAxisTitle(QwtPlot::yLeft, "Y Axis");
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->attach( plot );
    QwtPlotCurve *curve = new QwtPlotCurve();
    curve->setTitle( "Pixel Count" );
    curve->setPen(QPen(Qt::blue, 3) ),
    curve->setRenderHint( QwtPlotItem::RenderAntialiased, true);
    QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,QBrush(Qt::yellow),QPen(Qt::red,2),QSize(8,8));
    curve->setSymbol(symbol );
    for(i=0;i<n;i++)
    {
    QString result=read_data.at(i);
    result.remove(0,10);
    y[i]=result.toLatin1().toFloat();
    points<<QPointF(x[i],y[i]);
    }

    curve->setSamples( points );
    curve->attach(plot );
    plot->resize( 600, 400 );
    plot->show();
    @

    Is this is correct or anything mistake please help me to plot the data



  • Is there any example code for plotting the continuous data

    please provide me for reference



  • please any one have the idea about the real time data plotting???????????????


  • Moderators



  • I does not surprise me you get multiple QwtPlots: the second line in the for-loop creates a new one!

    It would be helpfull if you remove as much lines as possible in the code, as it boils down to this (note that I do not try to correct your coding style):

    @
    for(i=0;i<100000;i++)
    QwtPlot *plot = new QwtPlot();
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->attach(plot);
    QwtPlotCurve curve = new QwtPlotCurve();
    QPolygonF points = /
    ... */;
    curve->setSamples( points );
    curve->attach(plot );
    plot->resize( 600, 400 );
    plot->show();
    }
    @

    Perhaps it would be a good idea to delete all those pointers as well...

    More example at http://richelbilderbeek.nl/CppQwt.htm

    Good luck, Bilderbikkel



  • sorry for the late reply,

    I will check it out and reply to you


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.