ui->widget_ant1->plotLayout()->insertRow(0);ui->widget_ant1->plotLayout()->addElement(0, 0, new QCPTextElement(ui->widget_ant1, "天线1", QFont("Microsoft YaHei UI", 12, QFont::Bold)));//设置背景渐变色plotGradient.setColorAt(1, QColor(235, 235, 235));plotGradient.setColorAt(0, QColor(230, 230, 230));ui->widget_ant1->setBackground(plotGradient);//ui->widget_RSSI->axisRect()->setupFullAxesBox();//四边安装轴并显示ui->widget_ant1->rescaleAxes(true);ui->widget_ant1->xAxis->setBasePen(QPen(Qt::black,1));ui->widget_ant1->yAxis->setBasePen(QPen(Qt::black,1));ui->widget_ant1->xAxis2->setBasePen(QPen(Qt::black,1));ui->widget_ant1->yAxis2->setBasePen(QPen(Qt::black,1));ui->widget_ant1->xAxis->setSubTicks(false);ui->widget_ant1->xAxis2->setSubTicks(false);ui->widget_ant1->yAxis->setSubTicks(false);ui->widget_ant1->yAxis2->setSubTicks(false);ui->widget_ant1->xAxis->setTickPen(QPen(Qt::black,1));ui->widget_ant1->xAxis2->setTickPen(QPen(Qt::black,1));ui->widget_ant1->yAxis->setTickPen(QPen(Qt::black,1));ui->widget_ant1->yAxis2->setTickPen(QPen(Qt::black,1));ui->widget_ant1->xAxis->grid()->setZeroLinePen(QPen(Qt::black));//x轴0线颜色白色ui->widget_ant1->yAxis->grid()->setZeroLinePen(QPen(Qt::black));//y轴0线颜色白色ui->widget_ant1->xAxis2->grid()->setZeroLinePen(QPen(Qt::black));//x轴0线颜色白色ui->widget_ant1->yAxis2->grid()->setZeroLinePen(QPen(Qt::black));//y轴0线颜色白色ui->widget_ant1->xAxis->setRange(900,1000);ui->widget_ant1->xAxis->ticker()->setTickCount(5); //设置有多少刻度QVector<double> tickVector;for(int i = 0; i <= 1024; i++){tickVector.append(887.5 + ( + 25) / 1024 * i);}ui->widget_ant1->yAxis->setRange(0,100);ui->widget_ant1->yAxis->setLabel("10dB/div");ui->widget_ant1->yAxis->setTickLabelRotation(270);ui->widget_ant1->yAxis->ticker()->setTickCount(10); //设置有多少刻度ui->widget_ant1->yAxis2->setVisible(true);ui->widget_ant1->xAxis2->setVisible(true);ui->widget_ant1->xAxis2->setTickLabels(false);//隐藏刻度值ui->widget_ant1->yAxis2->setTickLabels(false);//隐藏刻度值ui->widget_ant1->yAxis->setTickLabels(false);//隐藏刻度值ui->widget_ant1->xAxis->setTickLabelColor(QColor(Qt::black));ui->widget_ant1->yAxis->setTickLabelColor(QColor(Qt::black));ui->widget_ant1->yAxis2->setTickLabelColor(QColor(Qt::black));ui->widget_ant1->xAxis2->setTickLengthIn(0);//主刻度向内延伸ui->widget_ant1->yAxis2->setTickLengthIn(5);//主刻度向内延伸//ui->widget_ber->legend->setVisible(true);ui->widget_ant1->replot();ui->widget_ant1->clearGraphs();ui->widget_ant1->addGraph();ui->widget_ant1->graph(0)->setPen(QPen(Qt::blue));//设置数据点的样式ui->widget_ant1->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle));for(int i = 0; i < 20; i++){ui->widget_ant1->graph(0)->addData(i, 50);}
运行图:
关于图像绘制样式的函数
//绘制一个点后跳过2个点
customPlot->graph(0)->setScatterSkip(2);//数据点显示图像
customPlot->graph(0)->setScatterStyle(QCPScatterStyle(QPixmap(":image/huaji.png")));//不显示连线
customPlot->graph(0)->setLineStyle(QCPGraph::LineStyle::lsNone);
关于clearGraphs()函数:
清除图像数据函数,清除后必须要重绘图像,图像才会显示空白
ui->widget_ant1->clearGraphs();ui->widget_ant1->replot();