所以我试图在 qcustomplot 的 x 轴上绘制时间...我的问题是如何让 x 轴的“滴答”,间隔为一小时 (00:00, 01 :00、02:00...等)。我的代码和结果如下:
代码:
ui->diagramArea->yAxis->setLabel("Thermocracy");
ui->diagramArea->yAxis->setRange(35,42);
ui->diagramArea->xAxis->setLabel("Hour of Measurement");
ui->diagramArea->xAxis->setTickLabelType(QCPAxis::ltDateTime);
ui->diagramArea->xAxis->setDateTimeFormat("hh:mm");
ui->diagramArea->xAxis->setRange(-7200,75600); //that's because im gmt+2
ui->diagramArea->xAxis->setAutoTickStep(3600);
ui->diagramArea->addGraph();
ui->diagramArea->graph(0)->setBrush(QBrush(QColor(204,243,255)));
ui->diagramArea->graph(0)->setPen(pen);
ui->diagramArea->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 5));
ui->diagramArea->graph(0)->setData(vTime,vData);
ui->diagramArea->replot();
结果:
最佳答案
尝试使用void QCPAxis::setTickStep(双步)
ui->diagramArea->xAxis->setAutoTickStep(false);
ui->diagramArea->xAxis->setTickStep(3600);
http://www.qcustomplot.com/documentation/classQCPAxis.html#a99fe77b034e06f5b723995beab96e741
whether the tick step, i.e. the interval between two (major) ticks, is calculated automatically. If on is set to true, the axis finds a tick step that is reasonable for human readable plots. The number of ticks the algorithm aims for within the visible range can be specified with setAutoTickCount.If on is set to false, you may set the tick step manually with setTickStep.
它采用 bool 变量,因此您似乎设置了自动计算的步骤。
关于c++ - 更改刻度间隔以使用一小时增量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26318378/