QAbstractBarSeries Class

The QAbstractBarSeries class is an abstract parent class for all bar series classes. More...

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 barsetsAdded(const QList<QBarSet *> &sets)
void barsetsRemoved(const QList<QBarSet *> &sets)
void clicked(int index, QBarSet *barset)
void countChanged()
void doubleClicked(int index, QBarSet *barset)
void hovered(bool status, int index, QBarSet *barset)
void labelsAngleChanged(qreal angle)
void labelsFormatChanged(const QString &format)
void labelsPositionChanged(QAbstractBarSeries::LabelsPosition position)
void labelsPrecisionChanged(int precision)
void labelsVisibleChanged()
void pressed(int index, QBarSet *barset)
void released(int index, QBarSet *barset)

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 the Charts with Widgets Gallery to learn how to use the QBarSeries class to create a simple bar chart.

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:

ConstantValueDescription
QAbstractBarSeries::LabelsCenter0Label is located in the center of the bar.
QAbstractBarSeries::LabelsInsideEnd1Label is located inside the bar at the top.
QAbstractBarSeries::LabelsInsideBase2Label is located inside the bar at the bottom.
QAbstractBarSeries::LabelsOutsideEnd3Label 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:

@valueThe 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:

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

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

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

See also append() and insert().

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

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

See also remove().

void QAbstractBarSeries::clear()

Removes all bar sets from the series and permanently deletes them.

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

This signal is emitted when the user clicks the bar specified by index in the bar set specified by barset.

int QAbstractBarSeries::count() const

Returns the number of bar sets in a bar series.

Note: Getter function for property count.

[signal] void QAbstractBarSeries::countChanged()

This signal is emitted when the number of bar sets is changed, for example by append() or remove().

Note: Notifier signal for property count.

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

This signal is emitted when the user double-clicks the bar specified by index in the bar set specified by barset.

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

This signal is emitted when a mouse is hovered over the bar specified by index in the bar set specified by barset. When the mouse moves over the bar, status turns true, and when the mouse moves away again, it turns false.

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.

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

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

Note: Notifier signal for property labelsAngle.

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

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

Note: Notifier signal for property labelsFormat.

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

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

Note: Notifier signal for property labelsPosition.

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

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

Note: Notifier signal for property labelsPrecision.

[signal] void QAbstractBarSeries::labelsVisibleChanged()

This signal is emitted when the labels' visibility changes.

Note: Notifier signal for property labelsVisible.

See also isLabelsVisible() and setLabelsVisible().

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

This signal is emitted when the user clicks the bar specified by index in the bar set specified by barset and holds down the mouse button.

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

This signal is emitted when the user releases the mouse press on the bar specified by index in the bar set specified by barset.

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.