QCustomPlot Discussion and Comments

Create a lot of lines on plotReturn to overview

In tutorial I see the sutuation where graphics(lines) created with help this code

// pass data points to graphs:
customPlot->graph(0)->setData(x0, y0);
customPlot->graph(1)->setData(x1, y1);
errorBars->setData(y1err);
customPlot->graph(2)->setData(x2, y2);
customPlot->graph(3)->setData(x3, y3);
customPlot->graph(4)->setData(x4, y4);

But in my program not constantly the quantity of lines.
For example I write in program 12 steps and my program drawing 12 lines-graphs(I tested in Visual Studio but my main task creating in the Qt Creator) in other I write 13 or 16 steps.

I write in loop but there is not right

void MainWindow::drawdifnet(int Nt)
{
    int N=Nt;
    int N1=pow(N,2);
    QVector<double> x22(N), y22(N1);
    int ii=0,jj=0;
    for (int j = 0; j < Nt ; j++)
            {
                for (int i = 0; i < Nt ; i++)//Было Nx
                {
                    x22[jj]=i;
                    y22[ii]=wht[j][i];
                    ui->widget_2->clearGraphs();
                    ui->widget_2->addGraph();
                    ui->widget_2->graph(0)->setData(x22,y22);
                    ui->widget_2->xAxis->setLabel("OsX");
                    ui->widget_2->yAxis->setLabel("OsY");
                    ui->widget_2->xAxis->setRange(Nt,Nt);
                    ui->widget_2->replot();
                    ii++;
                }
                jj++;
            }
}

this code only draws one plot. (graph 0)

you cant just set the data on the graph 100 times and have it draw 100 graphs. it will only draw the last one.

if you want to modify this code so that it would work, you can take lines 16 through 19 outside of the for loops. Line 13 needs to be removed. line 14 will return a pointer to a graph, which you would use on line 15 to set the data instead of 'ui->widget_2->graph(0)'.

Not drawing again.

At firs I think that my data is not seen in program.
I with help debugger check the data in

Qvector
and the arrays and QVector and the array correctly work and calculate.

void MainWindow::drawdifnet(int Nt)
{
    int N=Nt;
    int N1=pow(N,2);
    QVector<double> x22(N), y22(N1);
    int ii=0,jj=0;
    for (int j = 0; j < Nt ; j++)
            {
                for (int i = 0; i < Nt ; i++)
                {          

                    x22[jj]=i;
                    y22[ii]=wht[j][i];
                    ui->widget_2->addGraph();
                    ui->widget_2->graph(0)->setData(x22,y22);
                  ii++;
                }
                jj++;
    }
    ui->widget_2->xAxis->setLabel("OsX");
    ui->widget_2->yAxis->setLabel("OsY");
    ui->widget_2->xAxis->setRange(30,30);
    ui->widget_2->replot();
}

Instead setData,how?
In setData we added our points as I know or I not right?