- Qt 6.10
- Qt Graphs
- QML Types
- QtGraphs
- BarSeries
- Qt Graphs | Commercial or GPLv3

# BarSeries QML Type

Presents data in bar graphs. More...

Import Statement: | `import QtGraphs`
In C++: | QBarSeries
Inherits: | AbstractSeries

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

## Properties

- barDelegate : Component
- barSets : list<BarSet>
- barWidth : real
- barsType : enumeration
- borderColors : list<color>
- count : int
- labelsAngle : real
- labelsFormat : string
- labelsMargin : real
- labelsPosition : enumeration
- labelsPrecision : real
- labelsVisible : bool
- seriesColors : list<color>

## Signals

- barsetsAdded()
- barsetsRemoved()
- clicked(int index, BarSet barset)
- doubleClicked(int index, BarSet barset)
- pressed(int index, BarSet barset)
- released(int index, BarSet barset)

## Methods

- bool append(BarSet barset)
- BarSet at(int index)
- Barset at(int index)
- clear()
- int find(BarSet barset)
- BarSet insert(int index, BarSet barset)
- bool remove(BarSet barset)
- bool remove(int index)
- removeMultiple(int index, int count)
- bool replace(list<BarSet> sets)
- bool replace(BarSet oldSet, BarSet newSet)
- bool replace(int index, BarSet barset)

## Detailed Description

Draws data by default as a series of bars grouped by category, with one bar per category from each bar set added to the series. It also supports horizontal bars and grouping bars as stacked.

## Property Documentation

barDelegate : Component

A custom QML component used for visualizing each of the bars. Instance of this component is created for each of the bar. When this is not defined, a default rectangle visualization for bars is used.

The dynamic properties available for this component are:

Type | Name | Description
--- | --- | ---
color | barColor | The fill color of the bar. This value comes either from the GraphsTheme or from BarSet::color if the BarSet overrides the color.
color | barBorderColor | The border color of the bar. This value comes either from the GraphsTheme or from BarSet::borderColor if the BarSet overrides the color.
real | barBorderWidth | The width of the bar border. This value comes either from the GraphsTheme or from BarSet::borderWidth if the BarSet overrides the width.
real | barValue | The value of the bar. This value comes from the BarSet::values.
string | barLabel | The label of the bar. This value comes from the BarSet::label.
bool | barSelected | This value is true when the bar is selected, meaning that the bar index is in BarSet::selectedBars.
int | barIndex | Index of the bar, from 0 to the amount of bars - 1. [since 6.9]

To use any of these, add property with the defined name into your custom component. For example `"property color barColor"` and `"property real barValue"`.

barSets : list<BarSet> `[read-only]`

A list of sets added to the series.

barWidth : real

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.

By default, the barWidth is 0.5 (bars will take 50% of the available width). The valid values range from 0.0 (0%) to 1.0 (100%).

Note: When used with the BarSeries type, this value specifies the width of a group of bars instead of that of a single bar.

barsType : enumeration

The type of the bar series:

Constant | Description
--- | ---
`BarSeries.BarsType.Groups` | Bar sets are grouped by category. This is the default value.
`BarSeries.BarsType.Stacked` | Bar sets are stacked after each other by category.
`BarSeries.BarsType.StackedPercent` | Bar sets are stacked after each other by category. The segment size corresponds to the percentage of the segment value compared with the total value of all segments in the stack.

borderColors : list<color>

The list of border colors to be used for all the objects in the series.

If there are more series than colors, the color list wraps and starts again with the first color in the list. If this is not set (default), colors from the GraphsTheme::borderColors will be used.

count : int `[read-only]`

The number of bar sets in a bar series.

labelsAngle : real

The angle of the value labels in degrees.

labelsFormat : string

The format used for showing labels in a bar series.

See also QBarSeries::labelsFormat, labelsVisible, and labelsPosition.

labelsMargin : real

The margin of the value labels in pixels.

This margin from side is used when labelsPosition is set to something else than `LabelsPosition.Center`. The default value is `0`.

labelsPosition : enumeration

The position of the data value labels:

Constant | Description
--- | ---
`BarSeries.LabelsPosition.Center` | Label is located in the center of the bar.
`BarSeries.LabelsPosition.InsideEnd` | Label is located inside the bar at the top.
`BarSeries.LabelsPosition.InsideBase` | Label is located inside the bar at the bottom.
`BarSeries.LabelsPosition.OutsideEnd` | Label is located outside the bar at the top.

See also labelsVisible and labelsFormat.

labelsPrecision : real

The maximum amount of significant digits shown in value labels.

Default value is 6.

labelsVisible : bool

The visibility of the labels in a bar series. The default label visibility is `false`.

seriesColors : list<color>

The list of base colors to be used for all the objects in the series.

If there are more series than colors, the color list wraps and starts again with the first color in the list. If this is not set (default), colors from the GraphsTheme::seriesColors will be used.

## Signal Documentation

barsetsAdded()

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

Note: The corresponding handler is `onBarsetsAdded`.

barsetsRemoved()

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

Note: The corresponding handler is `onBarsetsRemoved`.

clicked(int index, BarSet barset)

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

Note: The corresponding handler is `onClicked`.

doubleClicked(int index, BarSet barset)

This signal is emitted when the user double-clicks or double-taps the bar specified by index in the bar set specified by barset. This signal always occurs after clicked.

Note: The corresponding handler is `onDoubleClicked`.

pressed(int index, BarSet barset)

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

Note: The corresponding handler is `onPressed`.

released(int index, BarSet barset)

This signal is emitted when the user releases a previously pressed mouse button or gesture on the bar specified by index in the bar set specified by barset.

Note: The corresponding handler is `onReleased`.

## Method Documentation

bool append(BarSet barset)

Adds a set of bars specified by barset 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.

See also insert().

BarSet at(int index)

Returns the bar set at index. Returns null if the index is not valid.

Barset at(int index)

Returns the bar set specified by index from the series. Returns `null` otherwise.

clear()

Removes all bar sets from the series.

int find(BarSet barset)

Returns the index of the bar set specified by barset from the series. Returns `-1` if not found.

BarSet insert(int index, BarSet barset)

Inserts a bar set specified by barset to a series at the position specified by index. If the set is `null` or already belongs to the series, the set is not appended. Returns `true` if inserting succeeds.

See also append().

bool remove(BarSet barset)

Removes the bar set specified by barset from the series. Returns `true` if successful, `false` otherwise.

bool remove(int index)

Removes the bar set specified by index from the series. Returns `true` if the removal was successful, `false` otherwise.

removeMultiple(int index, int count)

Removes a range of bar sets as specified by the index and count. The call traverses over all sets even if removal of one fails.

bool replace(list<BarSet> sets)

Completely replaces all current bar set with sets. The size does not need to match. Returns false if any of the bar set in sets are invalid.

bool replace(BarSet oldSet, BarSet newSet)

Replaces the bar set specified by oldSet with newSet. Returns `true` if the removal was successful, `false` otherwise. oldSet is destroyed if this is successful.

bool replace(int index, BarSet barset)

Replaces the bar set at the position specified by index from the series and replaces it with barset. Returns `true` if successful, `false` otherwise.