6.0.0-rc4Source

QAbstractBarSeries Class

The QAbstractBarSeries class is the base class of the bar series. More…

Header#include <QAbstractBarSeries>
CMaketarget_link_libraries(app PRIVATE Nt::Charts)
ModuleNt Charts C++ Classes
InheritsQAbstractSeries
Inherited byQBarSeries, QHorizontalBarSeries, QHorizontalPercentBarSeries, QHorizontalStackedBarSeries, QPercentBarSeries, QStackedBarSeries

List of all members, including inherited members

Public Types

Public Functions

~QAbstractBarSeries()
voidsetBarWidth(qreal width)
qrealbarWidth() const
boolappend(QBarSet *set)
boolremove(QBarSet *set)
booltake(QBarSet *set)
boolappend(const QList<QBarSet *> &sets)
boolinsert(int index, QBarSet *set)
intcount() const
QList<QBarSet *>barSets() const
voidclear()
voidsetLabelsVisible(bool visible = true)
boolisLabelsVisible() const
voidsetLabelsFormat(const QString &format)
QStringlabelsFormat() const
voidsetLabelsAngle(qreal angle)
qreallabelsAngle() const
voidsetLabelsPosition(QAbstractBarSeries::LabelsPosition position)
QAbstractBarSeries::LabelsPositionlabelsPosition() const
voidsetLabelsPrecision(int precision)
intlabelsPrecision() const

Signals

voidclicked(int index, QBarSet *barset)
voidhovered(bool status, int index, QBarSet *barset)
voidpressed(int index, QBarSet *barset)
voidreleased(int index, QBarSet *barset)
voiddoubleClicked(int index, QBarSet *barset)
voidcountChanged()
voidlabelsVisibleChanged()
voidlabelsFormatChanged(const QString &format)
voidlabelsPositionChanged(QAbstractBarSeries::LabelsPosition position)
voidlabelsAngleChanged(qreal angle)
voidlabelsPrecisionChanged(int precision)
voidbarsetsAdded(const QList<QBarSet *> &sets)
voidbarsetsRemoved(const QList<QBarSet *> &sets)

Protected Functions

QAbstractBarSeries(QObject *parent = nullptr)

Detailed Description

A bar series with three sets

A bar series holds QBarSet objects, and draws value i of each set at category i. The subclasses differ in how they put the sets together: side by side, stacked, or as percentages, with vertical or horizontal bars. The series owns its sets.

auto *done = new QBarSet("Done");
*done << 12 << 18 << 9 << 15;
auto *open = new QBarSet("Open");
*open << 4 << 6 << 3 << 8;

auto *series = new QBarSeries;
series->append(done);
series->append(open);
series->setLabelsVisible(true);
QObject::connect(series, &QBarSeries::clicked, [](int index, QBarSet *set) {
    std::printf("%s: %g\n", set->label().toUtf8().constData(), set->at(index));
});

auto *axisX = new QBarCategoryAxis;
axisX->append({"Core", "GUI", "Network", "Charts"});
auto *axisY = new QValueAxis;
axisY->setRange(0, 20);

auto *chart = new QChart;
chart->setTitle("Tickets");
chart->addSeries(series);
chart->addAxis(axisX, Qt::AlignBottom);
chart->addAxis(axisY, Qt::AlignLeft);
series->attachAxis(axisX);
series->attachAxis(axisY);

With setLabelsVisible(), each bar has a label with its value, written with labelsFormat().

See also QBarSet and QBarCategoryAxis.

Differences from Qt

Labels are drawn upright: labelsAngle() is kept but not used.

Member Type Documentation

enum QAbstractBarSeries::LabelsPosition

Where the value labels are drawn.

ConstantDescription
QAbstractBarSeries::LabelsCenterIn the middle of the bar.
QAbstractBarSeries::LabelsInsideEndInside the bar, at its end.
QAbstractBarSeries::LabelsInsideBaseInside the bar, at its base.
QAbstractBarSeries::LabelsOutsideEndBeyond the end of the bar.

Member Function Documentation

[explicit, protected] QAbstractBarSeries::QAbstractBarSeries(QObject *parent = nullptr)

Constructs an empty bar series with the given parent.

[override] QAbstractBarSeries::~QAbstractBarSeries()

Destroys the series and its sets.

bool QAbstractBarSeries::append(QBarSet *set)

Appends set to the series, which takes ownership of it. Returns false if set is nullptr or already in a series.

bool QAbstractBarSeries::append(const QList<QBarSet *> &sets)

This is an overloaded function.

Appends sets to the series. Returns false, and appends none of them, if one of them is nullptr, appears twice or is already in a series.

QList<QBarSet *> QAbstractBarSeries::barSets() const

Returns the sets.

[signal] void QAbstractBarSeries::barsetsAdded(const QList<QBarSet *> &sets)

This signal is emitted when sets are added to the series.

[signal] void QAbstractBarSeries::barsetsRemoved(const QList<QBarSet *> &sets)

This signal is emitted when sets are removed from the series.

qreal QAbstractBarSeries::barWidth() const

Returns the width of the bars, as a share of the room of a category.

void QAbstractBarSeries::clear()

Removes and deletes all sets.

[signal] void QAbstractBarSeries::clicked(int index, QBarSet *barset)

This signal is emitted when the user clicks the bar at index of barset.

int QAbstractBarSeries::count() const

Returns the number of sets.

[signal] void QAbstractBarSeries::countChanged()

This signal is emitted when the number of bar sets changes.

[signal] void QAbstractBarSeries::doubleClicked(int index, QBarSet *barset)

This signal is emitted when the user double-clicks the bar at index of barset.

[signal] void QAbstractBarSeries::hovered(bool status, int index, QBarSet *barset)

This signal is emitted when the mouse enters or leaves the bar at index of barset; status is true when it enters.

bool QAbstractBarSeries::insert(int index, QBarSet *set)

Inserts set at index; an index out of range appends it. Returns false if set is nullptr or already in a series.

bool QAbstractBarSeries::isLabelsVisible() const

Returns true if the value labels are drawn; otherwise returns false.

qreal QAbstractBarSeries::labelsAngle() const

Returns the angle of the value labels, in degrees.

[signal] void QAbstractBarSeries::labelsAngleChanged(qreal angle)

This signal is emitted when the angle of the value labels changes to angle.

QString QAbstractBarSeries::labelsFormat() const

Returns the format of the value labels.

[signal] void QAbstractBarSeries::labelsFormatChanged(const QString &format)

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

QAbstractBarSeries::LabelsPosition QAbstractBarSeries::labelsPosition() const

Returns where the value labels are drawn. The default is LabelsCenter.

[signal] void QAbstractBarSeries::labelsPositionChanged(QAbstractBarSeries::LabelsPosition position)

This signal is emitted when the position of the value labels changes to position.

int QAbstractBarSeries::labelsPrecision() const

Returns the number of significant digits of the value labels.

[signal] void QAbstractBarSeries::labelsPrecisionChanged(int precision)

This signal is emitted when the precision of the value labels changes to precision.

[signal] void QAbstractBarSeries::labelsVisibleChanged()

This signal is emitted when the value labels are shown or hidden.

[signal] void QAbstractBarSeries::pressed(int index, QBarSet *barset)

This signal is emitted when the user presses a mouse button on the bar at index of barset.

[signal] void QAbstractBarSeries::released(int index, QBarSet *barset)

This signal is emitted when the user releases a mouse button on the bar at index of barset.

bool QAbstractBarSeries::remove(QBarSet *set)

Removes set from the series and deletes it. Returns true on success.

void QAbstractBarSeries::setBarWidth(qreal width)

Sets the width of the bars to width, as a share of the room of a category: from 0 to 1. The sets of a QBarSeries share it. The default is 0.5.

void QAbstractBarSeries::setLabelsAngle(qreal angle)

Sets the angle of the value labels to angle degrees. Nt keeps the value and draws the labels upright.

void QAbstractBarSeries::setLabelsFormat(const QString &format)

Sets the format of the value labels to format. @value in it is replaced by the value of the bar, written with labelsPrecision() significant digits. The default is "@value".

void QAbstractBarSeries::setLabelsPosition(QAbstractBarSeries::LabelsPosition position)

Sets where the value labels are drawn to position.

void QAbstractBarSeries::setLabelsPrecision(int precision)

Sets the number of significant digits of the value labels to precision. The default is 6.

void QAbstractBarSeries::setLabelsVisible(bool visible = true)

Draws a label with its value on each bar if visible is true.

bool QAbstractBarSeries::take(QBarSet *set)

Removes set from the series without deleting it; the caller owns it. Returns true on success.