Łukasz Przeniosło
Łukasz Przeniosło

Reputation: 2949

QCustomPlot display time in HH:MM:SS

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?

Upvotes: 2

Views: 2691

Answers (2)

Glep Fingerman
Glep Fingerman

Reputation: 41

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

Upvotes: 0

m.s.
m.s.

Reputation: 16324

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().

Upvotes: 1

Related Questions