QCustomPlot 上的自定义刻度步骤 - QT

Custom tick step on QCustomPlot - QT

我是 QCustomPlot 的新手,但我无法创建 TickStep 的自定义大小。

现在,我有这个情节,(时间是从6:00到6:00另一天)。

我想要的 X 轴标签是什么:

我尝试使用 setTickStep 但没有成功。

    QVector<double> x(96), y(96); 

     for (int i=0; i<95; ++i)
     {
       x[i] = i*900+22500;
       y[i] = someValues loaded from db 

     }

     ui->customPlot->addGraph();

     ui->customPlot->setBackground(QBrush(QColor(239, 239, 239, 255)));
     ui->customPlot->graph(0)->setData(x, y);

     ui->customPlot->xAxis->setRange(21600, 108000);
     ui->customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
     ui->customPlot->xAxis->setDateTimeFormat("h:mm");

     //ui->customPlot->xAxis->setTickStep(7200);

在设置自定义刻度步骤之前,您错过了一件事。该功能称为:auto tick step 默认情况下在轴上启用,因此您需要先禁用它。

QVector<double> x(96), y(96);

for (int i=0; i<95; ++i)
{
  x[i] = i*900+22500;
  y[i] = i;  // some values not from database
}
ui->customPlot->addGraph();
ui->customPlot->setBackground(QBrush(QColor(239, 239, 239, 255)));
ui->customPlot->graph(0)->setData(x, y);

ui->customPlot->xAxis->setRange(21600, 108000);
ui->customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
ui->customPlot->xAxis->setDateTimeFormat("h:mm");

ui->customPlot->xAxis->setAutoTickStep(false);   // <-- disable to use your own value

ui->customPlot->xAxis->setTickStep(7200);

有和没有附加行的结果: