QT 折线图中 x 轴上的坐标不正确/自动调整

co-ordinates on x axis are incorrect / auto-adjusted in QT Line Chart

我正在 QT 5.7 中创建一个简单的折线图。

以下是我的certificate_page_childstable结构:

我的 C++ 代码:

QLineSeries *series = new QLineSeries();
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
QString db_path = QDir::currentPath();
db_path =  db_path + QString("/some_file");
db.setDatabaseName(db_path);
db.open();
QSqlQuery query;
 query.prepare("SELECT hardness_val FROM certificate_page_childs where cp_id=:value");
 query.bindValue(0,statisticalanalysis::cert_id_gbl);
 if(query.exec()){
      int d = 1;
      while (query.next()) {
          series->append(d, query.value(0).toDouble()); //Method 1
          //qDebug() << query.value(0).toString();
          //*series << QPointF(d,query.value(0).toDouble()); // Method 2
          qDebug() << d;
          d++;

      }
 }
 else
 {
     qDebug() << query.lastError();
 }
 db.close();
 QChart *chart = new QChart();
 chart->legend()->hide();
 chart->addSeries(series);
 chart->createDefaultAxes();
 chart->setTitle("Simple line chart example");
 chart->setAnimationOptions(QChart::SeriesAnimations);
 ui->graphicsView->setRenderHint(QPainter::Antialiasing);
 ui->graphicsView->setChart(chart);

以下是我的输出:

我需要什么:

X 轴:读数数量

Y 轴:每个读数的一些值

请将 x 轴与输出图像和所需图像进行比较。

谁能指导我达到预期的结果?

在这种特殊情况下,作为 X 轴,您的值是 1:1:n 您可以设置 tickCountlabelFormat:

QChart *chart = new QChart();
chart->legend()->hide();
chart->addSeries(series);
chart->createDefaultAxes();
chart->setTitle("Simple line chart example");
chart->setAnimationOptions(QChart::SeriesAnimations);
ui->graphicsView->setRenderHint(QPainter::Antialiasing);
ui->graphicsView->setChart(chart);
QValueAxis *axisX = static_cast<QValueAxis *>(chart->axisX(series)); // <--
axisX->setTickCount(series->count());  // <--
axisX->setLabelFormat("%d"); // <--