c++ - 更改刻度间隔以使用一小时增量?

标签 c++ qt qcustomplot

所以我试图在 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/

相关文章:

c++ - PoCo 日志记录。包含创建时间戳的日志文件名或每次应用程序启动时的新日志文件

c++ - 当程序失去焦点时 WH_FOREGROUNDIDLE 停止

c++ - 用 Qt 编写的可执行文件在 Fedora 16 和 18 上的行为有所不同

c++ - 如何存储Qt gui布局并恢复它

c++ - 如何在实时绘图中使用 QCustomPlot

c++ - QT无法通过上下文菜单添加新图(QCustomPlot)

c++ - 查找受其父约束的矩形的算法

c++ - 在 C++ 中,当函数按值返回对象时,在调用点应该调用复制构造函数

c++ - 如何设置 QComboBox 宽度以适合最大项目?

c++ - Qt Creator 的项目搞砸了