Reputation: 174
So i am trying to plot time on the x-axis of a qcustomplot... My problem is how i can have the "ticks" of the x-axis, have an interval of one hour (00:00, 01:00, 02:00... etc.). My code and the results are the following:
Code:
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();
Result:
Upvotes: 1
Views: 1598
Reputation: 18504
Try to use void QCPAxis::setTickStep ( double step)
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.
It takes bool variable, so it seems that you set automatically calculated steps.
Upvotes: 2