QCustomPlot Discussion and Comments

First example problemReturn to overview

Hi everybody,

I tried to draw the first example of the tutorial but I get a small and unreadable graph:
http://s30.postimg.org/76tvqy66p/Screen_Shot_2014_02_09_at_03_47_53_AM.png

My code is:

int main(int argc, char *argv[])
{

QApplication app(argc,argv);
QWidget fenetre;
fenetre.setFixedSize(500,500);

QCustomPlot *m_customPlot;
m_customPlot=new QCustomPlot(&fenetre);

QVector<double> y(101);
QVector<double> x(101);
for (int i=0; i<101; ++i)
{
x = i/50.0 - 1; // x goes from -1 to 1
y = x*x; // let's plot a quadratic function
}

// create graph and assign data to it:
m_customPlot->addGraph();
m_customPlot->graph(0)->setData(x,y);
// give the axes some labels:
m_customPlot->xAxis->setLabel("x");
m_customPlot->yAxis->setLabel("y");
// set axes ranges, so we see all data:
m_customPlot->xAxis->setRange(-1, 1);
m_customPlot->yAxis->setRange(0, 1);
m_customPlot->replot();

fenetre.show();
return app.exec();

}


Thanks a lot !

You're neither positioning the plot widget nor adding it to any layout that would position it. Have a look at the plot examples, or some tutorials on how to correctly use QtDesigner/QtCreator for form-generation.