I have trouble plotting multiple datapoints using QCPCurve
-
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 throughui->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.
-
Hi and welcome to devnet,
QCustomPlot is an independent project, you might want to check their forum for your issue.
-
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..