Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Problem in Real Time data plotting
QtWS25 Last Chance

Problem in Real Time data plotting

Scheduled Pinned Locked Moved 3rd Party Software
6 Posts 3 Posters 6.8k 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.
  • S Offline
    S Offline
    Swinetha
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Swinetha
      wrote on last edited by
      #2

      Is there any example code for plotting the continuous data

      please provide me for reference

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Swinetha
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          i have no experience with real time data plotting but goole spit out some results where you find some suggestions...

          • http://stackoverflow.com/questions/3848427/qt-best-way-to-implement-oscilloscope-like-realtime-plotting
          • http://qt-project.org/forums/viewthread/10677
          • http://stackoverflow.com/questions/12735734/real-time-data-plotting-with-qt-qwt-and-c

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • R Offline
            R Offline
            richelbilderbeek
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Swinetha
              wrote on last edited by
              #6

              sorry for the late reply,

              I will check it out and reply to you

              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