如何使用qtCustomplot绘制值

时间:2019-05-01 22:49:46

标签: c++ qt qcustomplot

我在Visual Studio中使用qt。当我编写此代码时-它不会绘制任何东西。它仅显示图形的背景,而不显示图形。

QCustomPlot plot;
QVector<double> x(101), y(101); // initialize with entries 0..100
for (int i = 0; i < 101; ++i)
{

    x[i] = i / 50.0 - 1; // x goes from -1 to 1
    y[i] = x[i] * x[i]; // let's plot a quadratic function
}
// create graph and assign data to it:
plot.addGraph();
plot.graph(0)->setData(x, y);
// give the axes some labels:
plot.xAxis->setLabel("x");
plot.yAxis->setLabel("y");
// set axes ranges, so we see all data:
plot.xAxis->setRange(-1, 1);
plot.yAxis->setRange(0, 1);
plot.replot();

enter image description here

0 个答案:

没有答案