Qt 5.7 | Qt Charts | C++ Classes | QAbstractBarSeries

Qt 5.7.1 Reference Documentation

# QAbstractBarSeries Class

Series for creating a bar chart. More...

Header: | #include <QAbstractBarSeries>
Instantiated By: | AbstractBarSeries
Inherits: | QAbstractSeries
Inherited By: | QBarSeries, QHorizontalBarSeries, QHorizontalPercentBarSeries, QHorizontalStackedBarSeries, QPercentBarSeries, and QStackedBarSeries

- List of all members, including inherited members

## Public Types

enum | LabelsPosition { LabelsCenter, LabelsInsideEnd, LabelsInsideBase, LabelsOutsideEnd }

## Properties

barWidth : qreal count : const int labelsAngle : qreal | labelsFormat : QString labelsPosition : LabelsPosition labelsVisible : bool

- 5 properties inherited from QAbstractSeries

## Public Functions

virtual | ~QAbstractBarSeries()
bool | append(QBarSet *set)
bool | append(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
bool | remove(QBarSet *set)
void | setBarWidth(qreal width)
void | setLabelsAngle(qreal angle)
void | setLabelsFormat(const QString &format)
void | setLabelsPosition(QAbstractBarSeries::LabelsPosition position)
void | setLabelsVisible(bool visible = true)
bool | take(QBarSet *set)

- 15 public functions inherited from QAbstractSeries

## Signals

void | barsetsAdded(QList<QBarSet *> sets)
void | barsetsRemoved(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 | labelsVisibleChanged()
void | pressed(int index, QBarSet *barset)
void | released(int index, QBarSet *barset)

- 4 signals inherited from QAbstractSeries

## Detailed Description

Series for creating a bar chart.

QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar and y-value is the height of the bar. The category names are ignored with this series and x-axis shows the x-values.

See the bar chart example to learn how to create a simple bar chart.

See also QBarSet, QStackedBarSeries, and QPercentBarSeries.

## Member Type Documentation

### enum QAbstractBarSeries::LabelsPosition

This enum describes the position of the data value labels.

Constant | Value | Description
--- | --- | ---
`QAbstractBarSeries::LabelsCenter` | `0` | Label is in the center of the bar.
`QAbstractBarSeries::LabelsInsideEnd` | `1` | Label is inside the bar at the high end of it.
`QAbstractBarSeries::LabelsInsideBase` | `2` | Label is inside the bar at the low end of it.
`QAbstractBarSeries::LabelsOutsideEnd` | `3` | Label is outside the bar at the high end of it.

## Property Documentation

### barWidth : qreal

The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. Note that with QBarSeries this value means the width of one group of bars instead of just one bar.

Access functions:

qreal | barWidth() const
void | setBarWidth(qreal width)

See also QBarSeries.

### count : const int

Holds the number of sets in series.

Access functions:

int | count() const

Notifier signal:

void | countChanged()

### labelsAngle : qreal

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

The format used for showing labels in 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 unit ('u'):

      series->setLabelsFormat("@value u");

By default, the labels shows the value of the bar. For percent bar series '%' is added after the value. The labels are shown on the plot area, labels on the edge of the plot area are cut. 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 QAbstractBarSeries::labelsVisible and QAbstractBarSeries::labelsPosition.

### labelsPosition : LabelsPosition

Defines 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 QAbstractBarSeries::labelsVisible and QAbstractBarSeries::labelsFormat.

### labelsVisible : bool

Defines the visibility of the labels in series

Access functions:

bool | isLabelsVisible() const
void | setLabelsVisible(bool visible = true)

Notifier signal:

void | labelsVisibleChanged()

## Member Function Documentation

### `[virtual]` QAbstractBarSeries::~QAbstractBarSeries()

Destructs abstractbarseries and owned barsets.

### bool QAbstractBarSeries::append(QBarSet *set)

Adds a set of bars to series. Takes ownership of set. If the set is null or is already in series, it won't be appended. Returns true, if appending succeeded.

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

Adds a list of barsets to series. Takes ownership of sets. Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series, nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended and function returns false.

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

Returns a list of sets in series. Keeps ownership of 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(QList<QBarSet *> sets)

This signal is emitted when sets have been added to the series.

See also append() and insert().

### `[signal]` void QAbstractBarSeries::barsetsRemoved(QList<QBarSet *> sets)

This signal is emitted when sets have been removed from the series.

See also remove().

### void QAbstractBarSeries::clear()

Removes all barsets from the series. Deletes removed sets.

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

The signal is emitted if the user clicks with a mouse on top of QBarSet barset. Clicked bar inside set is indexed by index

### int QAbstractBarSeries::count() const

Returns number of sets in series.

Note: Getter function for property count.

### `[signal]` void QAbstractBarSeries::countChanged()

This signal is emitted when barset count has been changed, for example by append or remove.

Note: Notifier signal for property count.

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

The signal is emitted if the user doubleclicks with a mouse on top of QBarSet barset. DoubleClicked bar inside set is indexed by index

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

The signal is emitted if mouse is hovered on top of series. Parameter barset is the pointer of barset, where hover happened. Parameter status is true, if mouse entered on top of series, false if mouse left from top of series. Hovered bar inside the set is indexed by index.

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

Insert a set of bars to series at index postion. Takes ownership of set. If the set is null or is already in series, it won't be appended. Returns true, if inserting succeeded.

### bool QAbstractBarSeries::isLabelsVisible() const

Returns the visibility of labels

Note: Getter function for property labelsVisible.

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

Signal is emitted when the angle of the value labels is changed.

Note: Notifier signal for property labelsAngle.

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

Signal is emitted when the format of data value labels is changed.

Note: Notifier signal for property labelsFormat.

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

Signal is emitted when the position of value labels is changed.

Note: Notifier signal for property labelsPosition.

### `[signal]` void QAbstractBarSeries::labelsVisibleChanged()

This signal is emitted when labels visibility have changed.

Note: Notifier signal for property labelsVisible.

See also isLabelsVisible() and setLabelsVisible().

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

The signal is emitted if the user presses with a mouse on top of QBarSet barset. Pressed bar inside set is indexed by index

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

The signal is emitted if the user releases with a mouse on top of QBarSet barset. Released bar inside set is indexed by index

### bool QAbstractBarSeries::remove(QBarSet *set)

Removes barset from series. Releases ownership of set. Deletes the set, if remove was successful. Returns true, if set was removed.

### void QAbstractBarSeries::setBarWidth(qreal width)

Sets the width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. Note that with this value means the width of one group of bars instead of just one bar.

Note: Setter function for property barWidth.

See also barWidth().

### void QAbstractBarSeries::setLabelsVisible(bool visible = true)

Sets the visibility of labels in 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 barset object.

NOTE: The series remains as the barset's parent object. You must set the parent object to take full ownership.

Returns true if take was successful.