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

qreal barWidth() const
int count() const
bool isLabelsVisible() const
qreal labelsAngle() const
QString labelsFormat() const
QAbstractBarSeries::LabelsPosition labelsPosition() const
int labelsPrecision() const
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)

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 the bar chart example 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.

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:

void labelsVisibleChanged()