2

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?

A. Sarid
  • 3,916
  • 2
  • 31
  • 56
wuhanmoon
  • 23
  • 4

2 Answers2

0

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.

A. Sarid
  • 3,916
  • 2
  • 31
  • 56
  • Thanks a lot. It really helps! – wuhanmoon Oct 10 '16 at 02:53
  • @wuhanmoon If this answer has solved your question please consider [accepting it](http://meta.stackexchange.com/q/5234/179419) by clicking the *V* mark next to it. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. – A. Sarid Oct 10 '16 at 08:50
0

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!

wuhanmoon
  • 23
  • 4