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

# Bars3DNode QML Type

3D bar graph node. More...

Import Statement: | `import QtGraphs`
Inherits: | GraphsNode

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

## Properties

- aspectRatio : real
- barSeriesMargin : size
- barSpacing : size
- barSpacingRelative : bool
- barThickness : real
- columnAxis : Category3DAxis
- customItemList : list<Custom3DItem>
- floorLevel : real
- gridLineType : Graphs3D.GridLineType
- horizontalAspectRatio : real
- labelMargin : real
- locale : locale
- margin : real
- multiSeriesUniform : bool
- optimizationHint : Graphs3D.OptimizationHint
- polar : bool
- primarySeries : Bar3DSeries
- queriedGraphPosition : vector3d
- radialLabelOffset : real
- rowAxis : Category3DAxis
- selectedElement : Graphs3D.ElementType
- selectedSeries : Bar3DSeries
- selectionMode : Graphs3D.SelectionMode
- seriesList : list<Bar3DSeries>
- theme : GraphsTheme
- valueAxis : ValueAxis3D

## Signals

- barSeriesMarginChanged(size margin)
- barSpacingChanged(size spacing)
- barSpacingRelativeChanged(bool relative)
- barThicknessChanged(real thicknessRatio)
- columnAxisChanged(Category3DAxis axis)
- floorLevelChanged(real level)
- multiSeriesUniformChanged(bool uniform)
- primarySeriesChanged(Bar3DSeries series)
- rowAxisChanged(Category3DAxis axis)
- selectedSeriesChanged(Bar3DSeries series)
- valueAxisChanged(ValueAxis3D axis)

## Methods

- qsizetype addCustomItem(Custom3DItem item)
- void addSeries(Bar3DSeries series)
- void clearSelection()
- void doPicking(QPoint point)
- void doRayPicking(QVector3D origin, QVector3D direction)
- bool hasSeries(Abstract3DSeries series)
- void insertSeries(int index, Bar3DSeries series)
- void releaseCustomItem(Custom3DItem item)
- void removeCustomItem(Custom3DItem item)
- void removeCustomItemAt(vector3d position)
- void removeCustomItems()
- void removeSeries(Bar3DSeries series)
- Abstract3DAxis selectedAxis()
- Custom3DItem selectedCustomItem()
- qsizetype selectedCustomItemIndex()
- int selectedLabelIndex()

## Detailed Description

This type enables developers to render a bar graph node in 3D with Qt Quick.

You will need to import Qt Graphs module to use this type:

     import QtGraphs

After that you can use Bars3DNode in your qml files:

     import QtQuick
     import QtGraphs

     View3D {
         width: 640
         height: 480

         Bars3DNode {
             width: parent.width
             height: parent.height

             Bar3DSeries {
                 itemLabelFormat: "@colLabel, @rowLabel: @valueLabel"

                 ItemModelBarDataProxy {
                     itemModel: dataModel
                     // Mapping model roles to bar series rows, columns, and values.
                     rowRole: "year"
                     columnRole: "city"
                     valueRole: "expenses"
                 }
             }
         }

         ListModel {
             id: dataModel
             ListElement{ year: "2022"; city: "Oulu";     expenses: "4200"; }
             ListElement{ year: "2022"; city: "Rauma";    expenses: "2100"; }
             ListElement{ year: "2022"; city: "Helsinki"; expenses: "7040"; }
             ListElement{ year: "2022"; city: "Tampere";  expenses: "4330"; }
             ListElement{ year: "2023"; city: "Oulu";     expenses: "3960"; }
             ListElement{ year: "2023"; city: "Rauma";    expenses: "1990"; }
             ListElement{ year: "2023"; city: "Helsinki"; expenses: "7230"; }
             ListElement{ year: "2023"; city: "Tampere";  expenses: "4650"; }
         }
     }

See also Bar3DSeries, ItemModelBarDataProxy, Scatter3DNode, Surface3DNode, and Qt Graphs C++ Classes for 3D.

## Property Documentation

aspectRatio : real

The ratio of the graph scaling between the longest axis on the horizontal plane and the y-axis. Defaults to `2.0`.

Note: Has no effect on Bars3D.

See also horizontalAspectRatio.

barSeriesMargin : size

Margin between series columns in X and Z dimensions. Preset to `(0.0, 0.0)` by default. Sensible values are on the range [0,1).

barSpacing : size

Bar spacing in X and Z dimensions.

Preset to `(1.0, 1.0)` by default. Spacing is affected by the barSpacingRelative property.

barSpacingRelative : bool

Whether spacing is absolute or relative to bar thickness.

If `true`, the value of `0.0` means that the bars are placed side-to-side, `1.0` means that a space as wide as the thickness of one bar is left between the bars, and so on. Preset to `true`.

barThickness : real

The bar thickness ratio between the X and Z dimensions. The value `1.0` means that the bars are as wide as they are deep, whereas `0.5` makes them twice as deep as they are wide.

columnAxis : Category3DAxis

The active column axis.

If an axis is not given, a temporary default axis with no labels is created. This temporary axis is destroyed if another axis is explicitly set to the same orientation.

customItemList : list<Custom3DItem>

The list of Custom3DItem items added to the graph. The graph takes ownership of the added items.

floorLevel : real

The floor level for the bar graph in Y-axis data coordinates.

The actual floor level will be restricted by the Y-axis minimum and maximum values. Defaults to zero.

gridLineType : Graphs3D.GridLineType

Defines whether the grid lines type is `Graphs3D.GridLineType.Shader` or `Graphs3D.GridLineType.Geometry`.

This value affects all grid lines.

See also Graphs3D.GridLineType.

horizontalAspectRatio : real

The ratio of the graph scaling between the x-axis and z-axis. The value of `0.0` indicates automatic scaling according to axis ranges. Defaults to `0.0`.

Note: Has no effect on Bars3DNode, which handles scaling on the horizontal plane via the barThickness and barSpacing properties. Polar graphs also ignore this property.

See also aspectRatio, polar, Bars3DNode::barThickness, and Bars3DNode::barSpacing.

labelMargin : real

This property specifies the margin for the placement of the axis labels.

Negative values place the labels inside the plot-area while positive values place them outside the plot-area. Label automatic rotation is disabled when the value is negative. Defaults to `0.1`

See also QAbstract3DAxis::labelAutoAngle.

locale : locale

Sets the locale used for formatting various numeric labels. Defaults to the `"C"` locale.

See also Value3DAxis::labelFormat.

margin : real

The absolute value used for the space left between the edge of the plottable graph area and the edge of the graph background.

If the margin value is negative, the margins are determined automatically and can vary according to the size of the items in the series and the type of the graph. The value is interpreted as a fraction of the y-axis range if the graph aspect ratios have not been changed from the default values. Defaults to `-1.0`.

Note: Setting a smaller margin for a scatter graph than the automatically determined margin can cause the scatter items at the edges of the graph to overlap with the graph background.

Note: On scatter and surface graphs, if the margin is small in comparison to the axis label size, the positions of the edge labels of the axes are adjusted to avoid overlap with the edge labels of the neighboring axes.

multiSeriesUniform : bool

Defines whether bars are to be scaled with proportions set to a single series bar even if there are multiple series displayed. If set to `true`, bar spacing will be correctly applied only to the X-axis. Preset to `false` by default.

optimizationHint : Graphs3D.OptimizationHint

Specifies whether the default or legacy mode is used for rendering optimization.

The default mode uses instanced rendering, and provides the full feature set at the best level of performance on most systems. The static mode optimizes graph rendering and is ideal for large non-changing data sets. It is slower with dynamic data changes and item rotations. Selection is not optimized, so using the static mode with massive data sets is not advisable. Legacy mode renders all items in th graph individually, without instancing. It should be used only if default mode does not work, that is the same as if the target system does not support instancing. Defaults to Default.

Note: On some environments, large graphs using static optimization may not render, because all of the items are rendered using a single draw call, and different graphics drivers support different maximum vertice counts per call. This is mostly an issue on 32bit and OpenGL ES2 platforms. To work around this issue, choose an item mesh with a low vertex count or use the point mesh.

See also Abstract3DSeries::mesh and Graphs3D.OptimizationHint.

polar : bool

If `true`, the horizontal axes are changed into polar axes. The x-axis becomes the angular axis and the z-axis becomes the radial axis. Polar mode is not available for bar graphs.

Defaults to `false`.

See also radialLabelOffset.

primarySeries : Bar3DSeries

The primary series of the graph. It is used to determine the row and column axis labels when the labels are not explicitly set to the axes.

If the specified series is not yet added to the graph, setting it as the primary series will also implicitly add it to the graph.

If the primary series itself is removed from the graph, this property resets to default.

If the series is null, this property resets to default. Defaults to the first added series or zero if no series are added to the graph.

queriedGraphPosition : vector3d `[read-only]`

This read-only property contains the latest graph position values along each axis queried using Scene3D::graphPositionQuery. The values are normalized to range `[-1, 1]`. If the queried position was outside the graph bounds, the values will not reflect the real position, but will instead be some undefined position outside the range `[-1, 1]`. The value will be undefined until a query is made.

There is no single correct 3D coordinate to match a particular screen position, so to be consistent, the queries are always done against the inner sides of an invisible box surrounding the graph.

Note: Bar graphs only allow querying graph position at the graph floor level, so the y-value is always zero for bar graphs and valid queries can be only made at screen positions that contain the floor of the graph.

See also Scene3D::graphPositionQuery.

radialLabelOffset : real

This property specifies the normalized horizontal offset for the axis labels of the radial polar axis. The value `0.0` indicates that the labels should be drawn next to the 0-angle angular axis grid line. The value `1.0` indicates that the labels are drawn in their usual place at the edge of the graph background. This property is ignored if the polar property value is `false`. Defaults to `1.0`.

See also polar.

rowAxis : Category3DAxis

The active row axis.

If an axis is not given, a temporary default axis with no labels is created. This temporary axis is destroyed if another axis is explicitly set to the same orientation.

selectedElement : Graphs3D.ElementType `[read-only]`

The element selected in the graph.

This property can be used to query the selected element type. The type is valid until a new selection is made in the graph and the `selectedElementChanged` signal is emitted.

The signal can be used for example for implementing customized input handling, as demonstrated by the Axis Handling example.

See also selectedLabelIndex(), selectedAxis(), selectedCustomItemIndex(), selectedCustomItem(), Bars3DNode::selectedSeries, Scatter3DNode::selectedSeries, Scene3D::selectionQueryPosition, and Graphs3D.ElementType.

selectedSeries : Bar3DSeries `[read-only]`

The selected series or `null`. If selectionMode has the `SelectionMultiSeries` flag set, this property holds the series that owns the selected bar.

selectionMode : Graphs3D.SelectionMode

The active selection mode in the graph. One of the graphs3d.selectionflag enum values.

seriesList : list<Bar3DSeries> `[default]`

The series of the graph. By default, this property contains an empty list. To set the series, either use the addSeries() function or define them as children of the graph.

theme : GraphsTheme

The active theme of the graph.

See also GraphsTheme.

valueAxis : ValueAxis3D

The active value axis.

If an axis is not given, a temporary default axis with no labels and an automatically adjusting range is created. This temporary axis is destroyed if another axis is explicitly set to the same orientation.

## Signal Documentation

barSeriesMarginChanged(size margin)

This signal is emitted when barSeriesMargin changes to margin.

Note: The corresponding handler is `onBarSeriesMarginChanged`.

barSpacingChanged(size spacing)

This signal is emitted when barSpacing changes to spacing.

Note: The corresponding handler is `onBarSpacingChanged`.

barSpacingRelativeChanged(bool relative)

This signal is emitted when barSpacingRelative changes to relative.

Note: The corresponding handler is `onBarSpacingRelativeChanged`.

barThicknessChanged(real thicknessRatio)

This signal is emitted when barThickness changes to thicknessRatio.

Note: The corresponding handler is `onBarThicknessChanged`.

columnAxisChanged(Category3DAxis axis)

This signal is emitted when columnAxis changes to axis.

Note: The corresponding handler is `onColumnAxisChanged`.

floorLevelChanged(real level)

This signal is emitted when floorLevel changes to level.

Note: The corresponding handler is `onFloorLevelChanged`.

multiSeriesUniformChanged(bool uniform)

This signal is emitted when multiSeriesUniform changes to uniform.

Note: The corresponding handler is `onMultiSeriesUniformChanged`.

primarySeriesChanged(Bar3DSeries series)

This signal is emitted when primarySeries changes to series.

Note: The corresponding handler is `onPrimarySeriesChanged`.

rowAxisChanged(Category3DAxis axis)

This signal is emitted when rowAxis changes to axis.

Note: The corresponding handler is `onRowAxisChanged`.

selectedSeriesChanged(Bar3DSeries series)

This signal is emitted when selectedSeries changes to series.

Note: The corresponding handler is `onSelectedSeriesChanged`.

valueAxisChanged(ValueAxis3D axis)

This signal is emitted when valueAxis changes to axis.

Note: The corresponding handler is `onValueAxisChanged`.

## Method Documentation

qsizetype addCustomItem(Custom3DItem item)

Adds a Custom3DItem item to the graph. Graph takes ownership of the added item.

Returns index to the added item if add was successful, -1 if trying to add a null item, and index of the item if trying to add an already added item.

See also removeCustomItems(), removeCustomItem(), and removeCustomItemAt().

void addSeries(Bar3DSeries series)

Adds the series to the graph. A graph can contain multiple series, but only one set of axes, so the rows and columns of all series must match for the visualized data to be meaningful. If the graph has multiple visible series, only the first one added will generate the row or column labels on the axes in cases where the labels are not explicitly set to the axes. If the newly added series has specified a selected bar, it will be highlighted and any existing selection will be cleared. Only one added series can have an active selection.

See also GraphsNode::hasSeries().

void clearSelection()

Clears selection from all attached series.

void doPicking(QPoint point)

Performs picking using view coordinates from point on the elements of the graph, selecting the first item hit. Default input handling performs this upon receiving the onTapped event.

See also selectedElement.

void doRayPicking(QVector3D origin, QVector3D direction)

Performs picking starting from origin and in direction on the elements of the graph, selecting the first item hit.

See also selectedElement.

bool hasSeries(Abstract3DSeries series)

Returns whether the series has already been added to the graph.

void insertSeries(int index, Bar3DSeries series)

Inserts the series into the position index in the series list. If the series has already been added to the list, it is moved to the new index.

Note: When moving a series to a new index that is after its old index, the new position in list is calculated as if the series was still in its old index, so the final index is actually the index decremented by one.

See also GraphsNode::hasSeries().

void releaseCustomItem(Custom3DItem item)

Gets ownership of item back and removes the item from the graph.

Note: If the same item is added back to the graph, the texture file needs to be re-set.

See also Custom3DItem::textureFile.

void removeCustomItem(Custom3DItem item)

Removes the custom item. Deletes the resources allocated to it.

void removeCustomItemAt(vector3d position)

Removes all custom items at position. Deletes the resources allocated to them.

void removeCustomItems()

Removes all custom items. Deletes the resources allocated to them.

void removeSeries(Bar3DSeries series)

Remove the series from the graph.

See also GraphsNode::hasSeries().

Abstract3DAxis selectedAxis()

Can be used to get the selected axis after receiving `selectedElementChanged` signal with any label type. Selection is valid until the next `selectedElementChanged` signal.

Returns the selected axis, or null.

See also selectedElement.

Custom3DItem selectedCustomItem()

Can be used to get the selected custom item after receiving `selectedElementChanged` signal with ElementType.CustomItem type. Ownership of the item remains with the graph. Selection is valid until the next `selectedElementChanged` signal.

Returns the selected custom item, or null.

See also selectedElement.

qsizetype selectedCustomItemIndex()

Can be used to query the index of the selected custom item after receiving `selectedElementChanged` signal with ElementType.CustomItem type. Selection is valid until the next `selectedElementChanged` signal.

Returns index of the selected custom item, or -1.

See also selectedElement.

int selectedLabelIndex()

Can be used to query the index of the selected label after receiving `selectedElementChanged` signal with any label type. Selection is valid until the next `selectedElementChanged` signal.

Returns index of the selected label, or -1.

See also selectedElement.