Reputation: 33
Im new in QCustomPlot but I am not able to create custom size of TickStep.
Right now, I have this plot, (time is from 6:00 to 6:00 another day).
And what is my desired X axis label:
I tried to play with setTickStep but without any success.
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);
Upvotes: 3
Views: 4684
Reputation: 7271
You have missed one thing before setting a custom tick step. The feature, called: auto tick step is enabled by default on the axes so you need to disable it first.
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);
The result with and without the additional line:
Upvotes: 3