Question

I have problem with QCustomPlot libarary. I made program where user inputs formula and x values then program calulates y values and displays them in nice table.

After that program uses x values and calculated y values to draw quadratic function. But instead of drawing curve it draws sharp lines. Like statistical diagram or somethink like that.

I would like to know how i can covert those for example

x- -1, -2, 1, 2, 0

y - -0.5, -0.25, 0.5, 0.25, 0

to a quadratic function.

if you need here is code where I draw graph.

kiek = 0;

    //limitas is just counter which counted how many times user typed values

   // user typed x values and calculated values are stored in double type array



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


    for(int z= 0; z<limitas; z++){

        x[z] = iksai[kiek];
        y[z] = d[kiek];
kiek++;

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

max = *std::max_element(d, d + limitas);

max1 = *std::max_element(iksai, iksai + limitas);

min1 = *std::min_element(d, d + limitas);

min = *std::min_element(iksai, iksai + limitas);

ui->customPlot->xAxis->setRange(min, max1);
ui->customPlot->yAxis->setRange(min1, max);

ui->customPlot->replot();
Was it helpful?

Solution

It is not QCustomPlot related question actually.

You must fill space between points with some splines. Here is a nice article that shows what splines are: http://cairnarvon.rotahall.org/2009/07/05/quadratic-spline-interpolation/

So basically you need two QCPGraph's.

First graph should hold your key points without any connection lines (QCPGraph::LineStyle::lsNone).

Second graph should hold calculated (by your code!) spline points with some resolution (for example, spline points for minX, minX+dx, minX+dx*2 .. maxX) and without scatters.

So you will get your points connected to each other with sexy curves.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top