QAbstractBarSeries Class
The QAbstractBarSeries class is an abstract parent class for all bar series classes. More...
| Header: | #include <QAbstractBarSeries> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Graphs) target_link_libraries(mytarget PRIVATE Qt6::Graphs) |
| qmake: | QT += graphs |
| Instantiated By: | AbstractBarSeries |
| Inherits: | QAbstractSeries |
| Inherited By: | |
| Status: | Technical Preview |
- List of all members, including inherited members
- QAbstractBarSeries is part of Qt Graphs 2D C++ Classes.
Public Types
| enum | LabelsPosition { LabelsCenter, LabelsInsideEnd, LabelsInsideBase, LabelsOutsideEnd } |
Properties
|
|
Public Functions
| virtual | ~QAbstractBarSeries() |
| bool | append(QBarSet *set) |
| bool | append(const QList<QBarSet *> &sets) |
| QList<QBarSet *> | barSets() const |
| qreal | barWidth() const |
| void | clear() |
| int | count() const |
| bool | insert(int index, QBarSet *set) |
| bool | isLabelsVisible() const |
| qreal | labelsAngle() const |
| QString | labelsFormat() const |
| QAbstractBarSeries::LabelsPosition | labelsPosition() const |
| int | labelsPrecision() const |
| bool | remove(QBarSet *set) |
| void | setBarWidth(qreal width) |
| void | setLabelsAngle(qreal angle) |
| void | setLabelsFormat(const QString &format) |
| void | setLabelsPosition(QAbstractBarSeries::LabelsPosition position) |
| void | setLabelsPrecision(int precision) |
| void | setLabelsVisible(bool visible = true) |
| bool | take(QBarSet *set) |
Signals
| void | countChanged() |
| void | labelsAngleChanged(qreal angle) |
| void | labelsFormatChanged(const QString &format) |
| void | labelsPositionChanged(QAbstractBarSeries::LabelsPosition position) |
| void | labelsPrecisionChanged(int precision) |
| void | labelsVisibleChanged() |
Detailed Description
In bar charts, bars are defined as bar sets that contain one data value for each category. The position of a bar is specified by the category and its height by the data value. Bar series that contain multiple bar sets group together bars that belong to the same category. The way the bars are displayed is determined by the subclass of this class chosen to create the bar chart.
If a QValueAxis is used instead of QBarCategoryAxis for the main bar axis, the bars are grouped around the index value of the category.
See also QBarSet, QBarSeries, QStackedBarSeries, QPercentBarSeries, QHorizontalBarSeries, QHorizontalStackedBarSeries, and QHorizontalPercentBarSeries.
Member Type Documentation
enum QAbstractBarSeries::LabelsPosition
This enum value describes the position of the data value labels:
| Constant | Value | Description |
|---|---|---|
QAbstractBarSeries::LabelsCenter | 0 | Label is located in the center of the bar. |
QAbstractBarSeries::LabelsInsideEnd | 1 | Label is located inside the bar at the top. |
QAbstractBarSeries::LabelsInsideBase | 2 | Label is located inside the bar at the bottom. |
QAbstractBarSeries::LabelsOutsideEnd | 3 | Label is located outside the bar at the top. |
Property Documentation
barWidth : qreal
This property holds the width of the bars of the series.
The unit of width is the unit of the x-axis. The minimum width for bars is zero, and negative values are treated as zero. Setting the width to zero means that the width of the bar on the screen is one pixel regardless of the scale of the x-axis. Bars wider than zero are scaled using the x-axis scale.
Note: When used with QBarSeries, this value specifies the width of a group of bars instead of that of a single bar.
Access functions:
| qreal | barWidth() const |
| void | setBarWidth(qreal width) |
See also QBarSeries.
[read-only] count : const int
This property holds the number of bar sets in a bar series.
Access functions:
| int | count() const |
Notifier signal:
| void | countChanged() |
labelsAngle : qreal
This property holds the angle of the value labels in degrees.
Access functions:
| qreal | labelsAngle() const |
| void | setLabelsAngle(qreal angle) |
Notifier signal:
| void | labelsAngleChanged(qreal angle) |
labelsFormat : QString
This property holds the format used for showing labels in a bar series.
QAbstractBarSeries supports the following format tag:
| @value | The value of the bar |
For example, the following usage of the format tags would produce labels that show the value followed by the unit (u):
series->setLabelsFormat("@value u");
By default, the labels show the value of the bar. For the percent bar series, % is added after the value. The labels are shown on the plot area, if the bars are close to each other, the labels may overlap.
Access functions:
| QString | labelsFormat() const |
| void | setLabelsFormat(const QString &format) |
Notifier signal:
| void | labelsFormatChanged(const QString &format) |
See also labelsVisible, labelsPosition, and labelsPrecision.
labelsPosition : LabelsPosition
This property holds the position of value labels.
Access functions:
| QAbstractBarSeries::LabelsPosition | labelsPosition() const |
| void | setLabelsPosition(QAbstractBarSeries::LabelsPosition position) |
Notifier signal:
| void | labelsPositionChanged(QAbstractBarSeries::LabelsPosition position) |
See also labelsVisible and labelsFormat.
labelsPrecision : int
This property holds the maximum amount of significant digits shown in value labels.
Default value is 6.
Access functions:
| int | labelsPrecision() const |
| void | setLabelsPrecision(int precision) |
Notifier signal:
| void | labelsPrecisionChanged(int precision) |
labelsVisible : bool
This property holds the visibility of the labels in a bar series.
Access functions:
| bool | isLabelsVisible() const |
| void | setLabelsVisible(bool visible = true) |
Notifier signal:
| void | labelsVisibleChanged() |
Member Function Documentation
[virtual noexcept] QAbstractBarSeries::~QAbstractBarSeries()
Removes the abstract bar series and the bar sets owned by it.
bool QAbstractBarSeries::append(QBarSet *set)
Adds a set of bars specified by set to the bar series and takes ownership of it. If the set is null or it already belongs to the series, it will not be appended. Returns true if appending succeeded.
bool QAbstractBarSeries::append(const QList<QBarSet *> &sets)
Adds a list of bar sets specified by sets to a bar series and takes ownership of the sets. Returns true if all sets were appended successfully. If any of the sets is null or was previously appended to the series, nothing is appended and this function returns false. If any of the sets appears in the list more than once, nothing is appended and this function returns false.
QList<QBarSet *> QAbstractBarSeries::barSets() const
Returns a list of bar sets in a bar series. Keeps the ownership of the bar sets.
qreal QAbstractBarSeries::barWidth() const
Returns the width of the bars of the series.
Note: Getter function for property barWidth.
See also setBarWidth().
void QAbstractBarSeries::clear()
Removes all bar sets from the series and permanently deletes them.
int QAbstractBarSeries::count() const
Returns the number of bar sets in a bar series.
Note: Getter function for property count.
bool QAbstractBarSeries::insert(int index, QBarSet *set)
Inserts a bar set specified by set to a series at the position specified by index and takes ownership of the set. If the set is null or already belongs to the series, it will not be appended. Returns true if inserting succeeds.
bool QAbstractBarSeries::isLabelsVisible() const
Returns the visibility of labels.
Note: Getter function for property labelsVisible.
bool QAbstractBarSeries::remove(QBarSet *set)
Removes the bar set specified by set from the series and permanently deletes it if the removal succeeds. Returns true if the set was removed.
void QAbstractBarSeries::setBarWidth(qreal width)
Sets the width of the bars of the series to width.
Note: Setter function for property barWidth.
See also barWidth().
void QAbstractBarSeries::setLabelsVisible(bool visible = true)
Sets the visibility of labels in a bar series to visible.
Note: Setter function for property labelsVisible.
See also isLabelsVisible().
bool QAbstractBarSeries::take(QBarSet *set)
Takes a single set from the series. Does not delete the bar set object.
Note: The series remains the barset's parent object. You must set the parent object to take full ownership.
Returns true if the take operation succeeds.