-1

I have a set of points to plot and their coordinates are stored in

QVector<double> x(200), y(200);

I'd like to connect them with some smooth curve, any, say, splines. Or a bigger array of points between knots would also suffice. My try is

    customPlot->addGraph();
    customPlot->graph(0)->setData(x, y);
    customPlot->graph(0)->setPen(QPen(Qt::blue));
    customPlot->xAxis->setLabel("Index");
    customPlot->yAxis->setLabel("Amplitude");
    customPlot->xAxis->setRange(0, 200);
    customPlot->yAxis->setRange(-3, 3);

I tried QPainterPath class, but it didn't work. Please, help me out.

UPD: I'm now looking through QEasingCurve class, these functions might help, but authors provide no examples and I don't know how to use them.

Dankevich
  • 194
  • 2
  • 12

1 Answers1

2

From the code I would say you are using QtCharts.

There is a QSplineSeries you can use that does exactly what you want.

Lifeisabug
  • 366
  • 2
  • 6
  • Is it possible to draw QSplineSeries on a QGraphicScene without using QtCharts? – Damir Porobic Nov 23 '16 at 08:30
  • No, that is not possible. If you want to do it by yourself you can check the code in splinechartitem.cpp of the QtCharts module. It is far from trivial though. – Lifeisabug Nov 24 '16 at 09:49
  • Yeah, I've noticed that already. I'm currently looking into some other alternatives, using bezier curves. http://stackoverflow.com/questions/40764011/how-to-draw-a-smooth-curved-line-that-goes-through-several-points-in-qt/40764363?noredirect=1#comment68756932_40764363 – Damir Porobic Nov 24 '16 at 10:18