QAbstractBarSeries Class
The QAbstractBarSeries class is the base class of the bar series. More…
| Header | #include <QAbstractBarSeries> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Charts) |
| Module | Nt Charts C++ Classes |
| Inherits | QAbstractSeries |
| Inherited by | QBarSeries, QHorizontalBarSeries, QHorizontalPercentBarSeries, QHorizontalStackedBarSeries, QPercentBarSeries, QStackedBarSeries |
List of all members, including inherited members
Public Types
| enum | LabelsPosition |
Public Functions
| ~QAbstractBarSeries() | |
| void | setBarWidth(qreal width) |
| qreal | barWidth() const |
| bool | append(QBarSet *set) |
| bool | remove(QBarSet *set) |
| bool | take(QBarSet *set) |
| bool | append(const QList<QBarSet *> &sets) |
| bool | insert(int index, QBarSet *set) |
| int | count() const |
| QList<QBarSet *> | barSets() const |
| void | clear() |
| void | setLabelsVisible(bool visible = true) |
| bool | isLabelsVisible() const |
| void | setLabelsFormat(const QString &format) |
| QString | labelsFormat() const |
| void | setLabelsAngle(qreal angle) |
| qreal | labelsAngle() const |
| void | setLabelsPosition(QAbstractBarSeries::LabelsPosition position) |
| QAbstractBarSeries::LabelsPosition | labelsPosition() const |
| void | setLabelsPrecision(int precision) |
| int | labelsPrecision() const |
Signals
| void | clicked(int index, QBarSet *barset) |
| void | hovered(bool status, int index, QBarSet *barset) |
| void | pressed(int index, QBarSet *barset) |
| void | released(int index, QBarSet *barset) |
| void | doubleClicked(int index, QBarSet *barset) |
| void | countChanged() |
| void | labelsVisibleChanged() |
| void | labelsFormatChanged(const QString &format) |
| void | labelsPositionChanged(QAbstractBarSeries::LabelsPosition position) |
| void | labelsAngleChanged(qreal angle) |
| void | labelsPrecisionChanged(int precision) |
| void | barsetsAdded(const QList<QBarSet *> &sets) |
| void | barsetsRemoved(const QList<QBarSet *> &sets) |
Protected Functions
| QAbstractBarSeries(QObject *parent = nullptr) |
Detailed Description

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.
| Constant | Description |
|---|---|
QAbstractBarSeries::LabelsCenter | In the middle of the bar. |
QAbstractBarSeries::LabelsInsideEnd | Inside the bar, at its end. |
QAbstractBarSeries::LabelsInsideBase | Inside the bar, at its base. |
QAbstractBarSeries::LabelsOutsideEnd | Beyond the end of the bar. |
Member Function Documentation
QAbstractBarSeries::QAbstractBarSeries(QObject *parent = nullptr)
Constructs an empty bar series with the given parent.
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.
void QAbstractBarSeries::barsetsAdded(const QList<QBarSet *> &sets)
This signal is emitted when sets are added to the series.
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.
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.
void QAbstractBarSeries::countChanged()
This signal is emitted when the number of bar sets changes.
void QAbstractBarSeries::doubleClicked(int index, QBarSet *barset)
This signal is emitted when the user double-clicks the bar at index of barset.
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.
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.
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.
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.
void QAbstractBarSeries::labelsPrecisionChanged(int precision)
This signal is emitted when the precision of the value labels changes to precision.
void QAbstractBarSeries::labelsVisibleChanged()
This signal is emitted when the value labels are shown or hidden.
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.
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.