DomantasB

10th November 2013, 19:36

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 tried QCP curve but i cant get it to work

I added this line of code But it shows total mess.

QCPCurve *newCurve = new QCPCurve(ui->customPlot->xAxis, ui->customPlot->yAxis);

ui->customPlot->addPlottable(newCurve);

newCurve->setName("Fermat's Spiral");

newCurve->setData(x, x, y);

I would like to know how i can draw graph with those kind of values and draw it like a curve. smoothly.

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();

Added after 1 4 minutes:

Ok i figured out its not related with QcustomPlot its all about spline interpolation. Can somebody explain me more about splines. I can understand them clearly

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 tried QCP curve but i cant get it to work

I added this line of code But it shows total mess.

QCPCurve *newCurve = new QCPCurve(ui->customPlot->xAxis, ui->customPlot->yAxis);

ui->customPlot->addPlottable(newCurve);

newCurve->setName("Fermat's Spiral");

newCurve->setData(x, x, y);

I would like to know how i can draw graph with those kind of values and draw it like a curve. smoothly.

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();

Added after 1 4 minutes:

Ok i figured out its not related with QcustomPlot its all about spline interpolation. Can somebody explain me more about splines. I can understand them clearly