2016-11-28 2 views
0

Я хочу сделать несколько графиков, таких как y = const в одной плоскости координат. Есть мой код:Графика QtCustomPlot не отображается

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; 

    QVector <QCPCurve> vecOfLines; 

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

К сожалению, отображается только координатная плоскость, но нет линий. Вы можете мне помочь?

ответ

0

Вы должны создать векторы x и y для каждого набора данных.

QVector<double> *x, *y; 
for(int i=0; i < numOfLines;++i) 
{  
    x = new QVector<double>; 
    y = new QVector<double>; 
    x->append(0); 
    x->append(max_x); 
    y->append(max_y/numOfLines +i+1); 
    y->append(max_y/numOfLines +i+1); 
    wGraphic->addGraph(wGraphic->xAxis, wGraphic->yAxis); 
    wGraphic->graph(i)->setData(*x,*y); 
} 
Смежные вопросы