BarSet QML Type | Qt Graphs | Qt 6.11.2
Description: Represents one set of bars in a bar graph.

- Qt 6.11
- Qt Graphs
- QML Types
- QtGraphs
- BarSet
- Qt Graphs | Commercial or GPLv3

# BarSet QML Type

Represents one set of bars in a bar graph. More...

Import Statement: | `import QtGraphs`
In C++: | QBarSet

- List of all members, including inherited members
- BarSet is part of Qt Graphs QML Types for 2D.

## Properties

- borderColor : color
- borderWidth : real
- color : color
- count : int
- label : string
- labelColor : color
- selectedBars : list
- selectedColor : color
- values : list<variant>

## Signals

- borderColorChanged(color)
- borderWidthChanged(real width)
- colorChanged(color)
- countChanged()
- labelChanged()
- labelColorChanged(color)
- selectedBarsChanged(list<int> indexes)
- selectedColorChanged(color color)
- update()
- updatedBars()
- valueAdded(int index, int count)
- valueChanged(int index)
- valueRemoved(int index, int count)
- valuesAdded(int index, int count)
- valuesChanged()
- valuesRemoved(int index, int count)

## Methods

- void append(list<real> values)
- void append(real value)
- real at(int index)
- void clear()
- int count()
- void deselectAllBars()
- void deselectBar(int index)
- void deselectBars(list<int> indexes)
- void insert(int index, real value)
- bool isBarSelected(int index)
- void remove(int index, int count)
- void replace(int index, real value)
- void selectAllBars()
- void selectBar(int index)
- void selectBars(list<int> indexes)
- void setBarSelected(int index, bool selected)
- real sum()
- void toggleSelection(list<int> indexes)

## Detailed Description

A bar set contains one data value for each category. The first value of a set is assumed to belong to the first category, the second one to the second category, and so on. If the set has fewer values than there are categories, the missing values are assumed to be located at the end of the set. For missing values in the middle of a set, the numerical value of zero is used. Labels for zero value sets are not shown.

See also BarSeries.

## Property Documentation

### borderColor : color

The border color of the bar set.

### borderWidth : real

By default, the width is -1, meaning the border width is defined by the theme.

### color : color

The fill color of the bar set.

### count : int `[read-only]`

The number of values in the bar set.

### label : string

The label of the bar set.

### labelColor : color

The text (label) color of the bar set.

### selectedBars : list `[read-only]`

The indexes of the bars which are currently selected.

### selectedColor : color

The fill color of the selected set.

### values : list<variant>

The values of the bar set. You can set a list of either real or point types as values.

If you set a list of real types as values, they directly define the bar set values.

If you set a list of point types as values, the x-coordinate of the point specifies its zero-based index in the bar set. The size of the bar set is the highest x-coordinate value + 1. If a point is missing for any x-coordinate between zero and the highest value, it gets the value zero.

For example, the following bar sets have equal values:

     myBarSet1.values = [5, 0, 1, 5];
     myBarSet2.values = [Qt.point(0, 5), Qt.point(2, 1), Qt.point(3, 5)];

## Signal Documentation

### borderColorChanged(color)

This signal is emitted when the border color of the bar set changes to color.

Note: The corresponding handler is `onBorderColorChanged`.

### borderWidthChanged(real width)

This signal is emitted when the barset's border width changes. The new width is width.

Note: The corresponding handler is `onBorderWidthChanged`.

### colorChanged(color)

This signal is emitted when the fill color of the bar set changes to color.

Note: The corresponding handler is `onColorChanged`.

### countChanged()

This signal is emitted when the barset's value count changes.

Note: The corresponding handler is `onCountChanged`.

### labelChanged()

This signal is emitted when the label of the bar set changes.

Note: The corresponding handler is `onLabelChanged`.

See also label.

### labelColorChanged(color)

This signal is emitted when the text (label) color of the bar set changes to color.

Note: The corresponding handler is `onLabelColorChanged`.

### selectedBarsChanged(list<int> indexes)

This signal is emitted when the selected bar changes. indexes is a list selected bar indexes.

Note: The corresponding handler is `onSelectedBarsChanged`.

### selectedColorChanged(color color)

This signal is emitted when the selected bar color changes. The new color is color.

Note: The corresponding handler is `onSelectedColorChanged`.

### update()

This signal is emitted when the barset is updated.

Note: The corresponding handler is `onUpdate`.

### updatedBars()

This signal is emitted when the bars in this set are updated.

Note: The corresponding handler is `onUpdatedBars`.

### valueAdded(int index, int count)

This signal is emitted when new values are added to the bar set. index indicates the position of the first inserted value, and count is the number of inserted values.

Note: The corresponding handler is `onValueAdded`.

### valueChanged(int index)

This signal is emitted when the value at the position specified by index is modified.

Note: The corresponding handler is `onValueChanged`.

### valueRemoved(int index, int count)

This signal is emitted when values are removed from the bar set. index indicates the position of the first removed value, and count is the number of removed values.

Note: The corresponding handler is `onValueRemoved`.

### valuesAdded(int index, int count)

This signal is emitted when new values are added to the bar set. index indicates the position of the first inserted value, and count is the number of inserted values.

Note: The corresponding handler is `onValuesAdded`.

### valuesChanged()

This signal is emitted when the values of the bar set change.

Note: The corresponding handler is `onValuesChanged`.

### valuesRemoved(int index, int count)

This signal is emitted when values are removed from the bar set. index indicates the position of the first removed value, and count is the number of removed values.

Note: The corresponding handler is `onValuesRemoved`.

## Method Documentation

### void append(list<real> values)

Appends the list of real values specified by values to the end of the bar set.

See also append().

### void append(real value)

Appends the new value specified by value to the end of the bar set.

### real at(int index)

Returns the value specified by index from the bar set. If the index is out of bounds, 0.0 is returned.

### void clear()

Removes all values from the set.

### int count()

Returns the number of values in a bar set.

### void deselectAllBars()

Deselects all bars in the set.

Note: Emits BarSet::selectedBarsChanged.

See also setBarSelected().

### void deselectBar(int index)

Deselects the bar at index.

Note: Emits BarSet::selectedBarsChanged.

See also setBarSelected().

### void deselectBars(list<int> indexes)

Marks multiple bars passed in an indexes list as deselected.

Note: Emits BarSet::selectedBarsChanged.

See also setBarSelected().

### void insert(int index, real value)

Inserts value in the position specified by index. The values following the inserted value are moved up one position.

See also remove().

### bool isBarSelected(int index)

Returns `true` if the bar at the given index is among selected bars and `false` otherwise.

Note: Selected bars are drawn using the selected color if it was specified using BarSet::setSelectedColor.

See also selectedBars, setBarSelected(), and selectedColor.

### void remove(int index, int count)

Removes the number of values specified by count from the bar set starting with the value specified by index.

If you leave out count, only the value specified by index is removed.

### void replace(int index, real value)

Adds the value specified by value to the bar set at the position specified by index.

### void selectAllBars()

Marks all bars in the set as selected.

Note: Emits BarSet::selectedBarsChanged.

See also setBarSelected().

### void selectBar(int index)

Marks the bar at index as selected.

Note: Emits BarSet::selectedBarsChanged.

See also setBarSelected().

### void selectBars(list<int> indexes)

Marks multiple bars passed in an indexes list as selected.

Note: Emits BarSet::selectedBarsChanged.

See also setBarSelected().

### void setBarSelected(int index, bool selected)

Marks the bar at index as either selected or deselected as specified by selected.

Note: Selected bars are drawn using the selected color if it was specified. Emits BarSet::selectedBarsChanged.

See also isBarSelected() and selectedColor.

### real sum()

Returns the sum of all values in the bar set.

### void toggleSelection(list<int> indexes)

Changes the selection state of bars at the given indexes to the opposite one.

Note: Emits BarSet::selectedBarsChanged.

See also setBarSelected().