6.0.0-rc4Source

QDateTimeAxis Class

The QDateTimeAxis class is an axis of dates and times. More…

Header#include <QDateTimeAxis>
CMaketarget_link_libraries(app PRIVATE Nt::Charts)
ModuleNt Charts C++ Classes
InheritsQAbstractAxis

List of all members, including inherited members

Public Functions

QDateTimeAxis(QObject *parent = nullptr)
~QDateTimeAxis()
voidsetMin(const QDateTime &min)
QDateTimemin() const
voidsetMax(const QDateTime &max)
QDateTimemax() const
voidsetRange(const QDateTime &min, const QDateTime &max)
voidsetFormat(const QString &format)
QStringformat() const
voidsetTickCount(int count)
inttickCount() const

Reimplemented Public Functions

AxisTypetype() const

Signals

voidminChanged(QDateTime min)
voidmaxChanged(QDateTime max)
voidrangeChanged(QDateTime min, QDateTime max)
voidformatChanged(const QString &format)
voidtickCountChanged(int tick)

Reimplemented Protected Functions

voidsetRangeFromVariant(const QVariant &min, const QVariant &max)

Detailed Description

A line series against a date and time axis

The series attached to the axis give their x (or y) values in milliseconds since 1970-01-01T00:00:00 UTC, as QDateTime::toMSecsSinceEpoch() returns them. The axis has tickCount() ticks spread evenly over its range, with labels written with format():

auto *series = new QLineSeries;
series->append(QDateTime::currentDateTime().toMSecsSinceEpoch(), cpuLoad());

auto *axisX = new QDateTimeAxis;
axisX->setFormat("hh:mm:ss");
axisX->setTickCount(6);
chart->addAxis(axisX, Qt::AlignBottom);
series->attachAxis(axisX);

See also QValueAxis and QDateTime::toString().

Differences from Qt

The labels are written in local time.

Member Function Documentation

[explicit] QDateTimeAxis::QDateTimeAxis(QObject *parent = nullptr)

Constructs a date and time axis with the given parent.

[override] QDateTimeAxis::~QDateTimeAxis()

Destroys the axis.

QString QDateTimeAxis::format() const

Returns the format of the labels.

[signal] void QDateTimeAxis::formatChanged(const QString &format)

This signal is emitted when the format of the labels changes to format.

QDateTime QDateTimeAxis::max() const

Returns the maximum of the axis.

[signal] void QDateTimeAxis::maxChanged(QDateTime max)

This signal is emitted when the maximum of the axis changes to max.

QDateTime QDateTimeAxis::min() const

Returns the minimum of the axis.

[signal] void QDateTimeAxis::minChanged(QDateTime min)

This signal is emitted when the minimum of the axis changes to min.

[signal] void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max)

This signal is emitted when the range of the axis changes to min and max.

void QDateTimeAxis::setFormat(const QString &format)

Sets the format of the labels to format, as QDateTime::toString() reads it. The default is "dd-MM-yyyy h:mm".

void QDateTimeAxis::setMax(const QDateTime &max)

Sets the maximum of the axis to max. The minimum shrinks to max if it is later.

void QDateTimeAxis::setMin(const QDateTime &min)

Sets the minimum of the axis to min. The maximum grows to min if it is earlier.

void QDateTimeAxis::setRange(const QDateTime &min, const QDateTime &max)

Sets the range of the axis to min and max. A range that ends before it starts is ignored.

[override, protected] void QDateTimeAxis::setRangeFromVariant(const QVariant &min, const QVariant &max)

Reimplements QAbstractAxis::setRangeFromVariant().

Sets the range to min and max, converted to QDateTime. An invalid variant leaves that end as it is.

void QDateTimeAxis::setTickCount(int count)

Sets the number of ticks to count, at least 2.

int QDateTimeAxis::tickCount() const

Returns the number of ticks. The default is 5.

[signal] void QDateTimeAxis::tickCountChanged(int tick)

This signal is emitted when the number of ticks changes to tick.

[override] AxisType QDateTimeAxis::type() const

Reimplements QAbstractAxis::type().

Returns QAbstractAxis::AxisTypeDateTime.