Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I have trouble plotting multiple datapoints using QCPCurve
Qt 6.11 is out! See what's new in the release blog

I have trouble plotting multiple datapoints using QCPCurve

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 728 Views 1 Watching
  • 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.
  • M Offline
    M Offline
    MegAmaNeo1
    wrote on last edited by
    #1

    Hello!
    I would like to plot multiple datapoints to my widget using QCustomPlot.
    The graph they will resemble will have multiple y-Values assigned to the same x-value, which is why using "Graph" did not get me anyhwere.
    Initially, I defined a QVector whose values I plotted through

    ui->customPlot->graph(0)->setData(x,y);

    However - as I said - this doesn't help me since I need to be able to manually control the order of connection of points.

    After research I learned that I need to use QCPCurve by defining:

    QCPCurve *newCurve = new QCPCurve(ui->plot->xAxis, ui->plot->yAxis); (1)
    ui->customPlot->addPlottable(this->newCurve); (2)

    Allegedly I should now be able to plot the points by using a QVector as I was used to do it using "Graph" by writing:
    this->newCurve->setData(x, y);

    The problem I have is that line (2) and (3) give me the the following error messages:

    'class QCustomPlot' has no member named 'addPlottable'; did you mean 'hasPlottable'?
    'class MainWindow' has no member named 'newCurve'
    unused variable 'new Curve' [-Wunused-variable]
    'class MainWindow' has no member named 'newCurve'

    Every thread I searched simply stated that I have to implement these three lines (1) (2) (3).
    I think that my problem lies in needing to define the Plottable for QCP or sth like that.
    I am a complete beginner and all these things do not say anything to me..

    I will attach my code below so you have more information, can anyone explain me what the nature of the problem is?

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        QCPCurve *newCurve = new QCPCurve(ui->plot->xAxis, ui->plot->yAxis);
    
         ui->plot->addPlottable (this->newCurve);
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::on_btn_start_clicked()
    {
    QVector<double> x(1),y(1);
    x[0] = 1;
    y[0] = 2;
    
    this->newCurve->setData(x,y);
    }
    

    This is my mainwindow.cpp class.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      QCustomPlot is an independent project, you might want to check their forum for your issue.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MegAmaNeo1
        wrote on last edited by MegAmaNeo1
        #3

        Thank you for the information. I posted a thread there too now.
        If its ok I would leave this thread in case anyone can help..

        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