需要加 QT += charts
//全局变量
QScatterSeries *series2=NULL;
//创建chart:
ui->lineEdit_4->setValidator(new QIntValidator(ui->lineEdit_4));//lineEdit只能输入数字
QFont font;
font.setPixelSize(12);
QVBoxLayout *layout = new QVBoxLayout;
layout->setMargin(0);
QChartView *qcv=new QChartView();
layout->addWidget(qcv);
ui->widget_chart->setLayout(layout);
QChart *chart2 = new QChart();
series2 = new QScatterSeries();
series2->setMarkerShape(QScatterSeries::MarkerShape::MarkerShapeCircle);
series2->setMarkerSize(8);
series2->append(16,0.5);
series2->append(20,0.7);
series2->append(30,0.3);
series2->append(40,0.2);
chart2->addSeries(series2);
chart2->createDefaultAxes();//设置默认网格
chart2->axes(Qt::Horizontal).first()->setRange(0, 100);//设置x轴范围 细胞大小
chart2->axes(Qt::Horizontal).first()->setTitleFont(font);
chart2->axes(Qt::Horizontal).first()->setTitleText(tr("Cell size/um"));
chart2->axes(Qt::Vertical).first()->setRange(0, 1);//设置y轴范围 细胞圆度
chart2->axes(Qt::Vertical).first()->setTitleFont(font);
chart2->axes(Qt::Vertical).first()->setTitleText(tr("Cell roundness"));
qcv->setRenderHint(QPainter::Antialiasing);//设置抗锯齿
qcv->resize(ui->widget_chart->size());
qcv->setChart(chart2);
qcv->chart()->legend()->hide();
//清除结果
series2->clear();