QCustomPlot Discussion and Comments

rescaleKeyAxis() works incorrectly?Return to overview

Good day!!!

int numPoints = 100;

double *arrayX = new double[numPoints];
double *arrayY = new double[numPoints];

for(int j = 0; j < numPoints; j++){
    arrayX[j] = j;
    arrayY[j] = qSin(j);
}

//Attention!!!
arrayY[0] = -0.5;
arrayY[numPoints-1] = 0.5;

arrayX[0] = 3;
arrayX[numPoints-1] = 7;


QVector<double> vectorX;
QVector<double> vectorY;

std::copy(arrayX, arrayX + numPoints, std::back_inserter(vectorX));
std::copy(arrayY, arrayY + numPoints, std::back_inserter(vectorY));

customPlot->addGraph();
customPlot->graph(0)->setData(vectorX, vectorY, true);

//case1 - work incorrect? https://imgur.com/KP1APlV
customPlot->graph(0)->rescaleKeyAxis();
//case2 - work ok https://imgur.com/a/a5Ndu
customPlot->graph(0)->rescaleValueAxis();
//case3 - work incorrect? (its call rescaleKeyAxis() and rescaleValueAxis() ) https://imgur.com/a/l9fbG
customPlot->graph(0)->rescaleAxes();

It is a bug or am I doing something wrong?

Why do you pass "true" when calling

customPlot->graph(0)->setData(vectorX, vectorY, true);

? Did you read the documentation for setData?

Because I don't want the data to be sorted by key.
I thought QCustomPlot can draw graph, where X[j-1] > X[j]. Am I wrong?

Oh!
Sorry! My mistake!
I have to use QCPCurve!
The problem is closed! Thanks!