QCustomPlot Discussion and Comments

No graphics appearedReturn to overview

Hello!
I want to make several graphics like y=const in one coordinate plane. There is my code:

TimeDiagram::TimeDiagram(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::TimeDiagram)
{
    ui->setupUi(this);
    wGraphic = new QCustomPlot();
    ui->verticalLayout->addWidget(wGraphic);
 
    int max_x=10;
    int max_y=10;
 
    for(int i=0; i < numOfLines;++i)
    {
        QVector<double> x(2), y(2);
        x[0]=0;
        x[1]=max_x;
        y[0]= max_y/numOfLines +i+1;
        y[1]= max_y/numOfLines +i+1;
        wGraphic->addGraph(wGraphic->xAxis, wGraphic->yAxis);
        wGraphic->graph(i)->setData(x,y);
    }
 
    wGraphic->replot();
}

Sadly, only coordinate plane appears but no lines. Can you help me?

In line 17 and 18 you're doing an integer division max_x/numOfLines is that intentional? You might want to do max_x/(double)numOfLines instead.

Other than this, the code looks okay. Try calling wGraphic->rescaleAxes() to see the full extent of your set of lines. Further, make sure numOfLines is the correct value that you expect.