Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How can i get y value from a plotted QCustomPlot?



  • Hi,

    My data is already plotted on:

    ui->cumstomPlot_1
    

    And now i need to read this data (256 "y" values), sum each value ( from this y axis) and write a new file with this this code:

    for(int i=0; i<257; ++i)
        {
    //Here I want to create a new double ("new_y") variable to receive the y value indexed by "i"  (in this case my "x" axis)
            double r =  QRandomGenerator::global()->bounded(-100,100);
            df<< QString("%1").arg(i) + "," + QString("%1").arg(new_y+(r/10));
            df <<"\n";
    
            qDebug() << r;
        }
    //from this point on, i know what I  must have to do.
    

    Thanks



  • Hi,
    Someone could help me, please!!!


  • Lifetime Qt Champion

    Hi
    Actually QCustomPlot is not part of Qt and have its own support forum.
    https://www.qcustomplot.com/index.php/support/forum

    We would tell you if we knew but so far no user seems to know the answer here.



  • Ok. Thanks.



  • @mrjj I solved the problem and I will post here just in case someone needs:

    ...

        for (int i=0;i<256;++i){
         double lastKey = (ui->customPlot_1->graph(0)->data()->at(i)->key);
         double lastValue = (ui->customPlot_1->graph(0)->data()->at(i)->value);
         qDebug () << "X:" << i << lastKey;
         qDebug () << "Y:" << i << lastValue;
    }

  • Lifetime Qt Champion

    Hi,

    You can improve your access to the data using:

    auto plotData = ui->customPlot_1->graph(0)->data();
    for (int i = 0 ; i < plotData->size() ; ++i) {
         double lastKey = plotData->at(i)->key;
         double lastValue = plotData->at(i)->value);
         qDebug () << "X:" << i << lastKey;
         qDebug () << "Y:" << i << lastValue;
    }
    

    Or use iterators.


Log in to reply