因工作需要,研究了QCustomplot官方代码中关于QCPCurve中的部分,此代码为官方源码中提取的个例
// create empty curve objects:
QCPCurve *fermatSpiral1 = new QCPCurve(customPlot->xAxis, customPlot->yAxis); //创建实例对象
const int pointCount = 500; //数据量
QVector<QCPCurveData> dataSpiral1(pointCount); //元素数组
for (int i=0; i<pointCount; ++i)
{
double phi = i/(double)(pointCount-1)*8*M_PI;
double theta = i/(double)(pointCount-1)*2*M_PI;
dataSpiral1[i] = QCPCurveData(i, qSqrt(phi)*qCos(phi), qSqrt(phi)*qSin(phi));
//dataSpiral1[i] = QCPCurveData(i, key, value);
//t->生成点的个数,key->x轴,value->y轴
}
// pass the data to the curves; we know t (i in loop above) is ascending, so set alreadySorted=true (saves an extra internal sort):
fermatSpiral1->data()->set(dataSpiral1, true);
// color the curves:
fermatSpiral1->setPen(QPen(Qt::blue));
fermatSpiral1->setBrush(QBrush(QColor(0, 0, 255, 20)));
上面代码生成结果
其中函数: QCPCurveData(i, key, value);
t->生成点的个数,key->x轴,value->y轴