QCustomPlot display time in HH:MM:SS

2.4k views Asked by At

I was wondering either it is possible in the QCustomPlot library to change display format of the data on one of the axis. In my application on the X axis I have time in seconds and I would like to display the steps in HH:MM:SS instead. As an alternative I am thinking of changing the display only from seconds to minutes to hours depending on the X lenght and updating the label from Time [s] to [min] to [hour]. But I would avoid that if its possible to do it the way I described. I Would appreciate all help!

When using:

customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
customPlot->xAxis->setDateTimeFormat("hh:mm:ss");

My timeline starts from hour 1 instead of 0: enter image description here Is there a way to fix this?

2

There are 2 answers

0
m.s. On BEST ANSWER

You can use setTickLabelType() and setDateTimeFormat:

plot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
plot->xAxis->setDateTimeFormat("hh:mm:ss");

The format string is built according to the the format string of QDateTime::toString().

0
Glep Fingerman On
// Создаем формат отображения дискретных отсчетов времени захвата мгновенного курса судна
QSharedPointer<QCPAxisTickerDateTime> dateTicker(new QCPAxisTickerDateTime);
// Установка формата отображения времени захвата мгновенного курса судна
dateTicker->setDateTimeFormat("hh:mm:ss");
// Передаем вектор подписей в график
m_QCustomPlot->yAxis->setTicker(dateTicker);