Reputation: 23
Here are some example points:
(1,1),(2,3),(3,1),(4,2),(1,5),(3,4)
I want to plot these points with a line in turn, I've added them into the vector x
and y
. Then, setData(x,y)
was performed.
However, the QCustomPlot
seems like can only plot points by the order of x
axis.
I noticed the points were sorted automatically by the setData(x,y)
.
How can I do to plot these points by the original order?
Upvotes: 2
Views: 1567
Reputation: 3996
What you are looking for is using QCPCurve
instead of Graph.
Define:
QCPCurve *newCurve;
And initiate it by doing:
this->newCurve = new QCPCurve(ui->customPlot->xAxis, ui->customPlot->yAxis);
ui->customPlot->addPlottable(this->newCurve);
Then you can use it the same way as you did with the Graph:
QVector<double> x, y;
//...
this->newCurve->setData(x, y);
See also this example: Parametric Curves Demo.
Upvotes: 0
Reputation: 23
Based on A. Sarid’ help, I found the usage of QCPCurve in the demos(11). The difference between QCPCurve and QCPGraph is that one x can correspond to different y with QCPCurve. So, just add the code:
QCPCurve *newCurve = new QCPCurve(ui->customPlot->xAxis, ui->customPlot->yAxis); newCurve->setData(x,y);
Thanks to A. Sarid again!
Upvotes: 0