Q3DBars Class
The Q3DBars class provides methods for rendering 3D bar graphs. More...
Header: | #include <Q3DBars> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS DataVisualization) target_link_libraries(mytarget PRIVATE Qt6::DataVisualization) |
qmake: | QT += datavisualization |
Since: | QtDataVisualization 1.0 |
Inherits: | QAbstract3DGraph |
Properties
|
|
Public Functions
virtual | ~Q3DBars() |
QList<QAbstract3DAxis *> | axes() const |
QSizeF | barSeriesMargin() const |
QSizeF | barSpacing() const |
float | barThickness() const |
QCategory3DAxis * | columnAxis() const |
float | floorLevel() const |
bool | isBarSpacingRelative() const |
bool | isMultiSeriesUniform() const |
QBar3DSeries * | primarySeries() const |
QCategory3DAxis * | rowAxis() const |
QBar3DSeries * | selectedSeries() const |
QList<QBar3DSeries *> | seriesList() const |
void | setBarSeriesMargin() |
void | setBarSpacing() |
void | setBarSpacingRelative() |
void | setBarThickness() |
void | setColumnAxis() |
void | setFloorLevel() |
void | setMultiSeriesUniform() |
void | setPrimarySeries() |
void | setRowAxis() |
void | setValueAxis() |
QValue3DAxis * | valueAxis() const |
Signals
void | barSeriesMarginChanged() |
void | barSpacingChanged() |
void | barSpacingRelativeChanged() |
void | barThicknessChanged() |
void | columnAxisChanged() |
void | floorLevelChanged() |
void | multiSeriesUniformChanged() |
void | primarySeriesChanged() |
void | rowAxisChanged() |
void | selectedSeriesChanged() |
void | valueAxisChanged() |
Detailed Description
This class enables developers to render bar graphs in 3D and to view them by rotating the scene freely. Rotation is done by holding down the right mouse button and moving the mouse. Zooming is done by mouse wheel. Selection, if enabled, is done by left mouse button. The scene can be reset to default camera view by clicking mouse wheel. In touch devices rotation is done by tap-and-move, selection by tap-and-hold and zoom by pinch.
If no axes are set explicitly to Q3DBars, temporary default axes with no labels are created. These default axes can be modified via axis accessors, but as soon any axis is set explicitly for the orientation, the default axis for that orientation is destroyed.
Q3DBars supports more than one series visible at the same time. It is not necessary for all series to have the same amount of rows and columns. Row and column labels are taken from the first added series, unless explicitly defined to row and column axes.
How to construct a minimal Q3DBars graph
First, construct an instance of Q3DBars. Since we are running the graph as top level window in this example, we need to clear the Qt::FramelessWindowHint
flag, which gets set by default:
Q3DBars bars; bars.setFlags(bars.flags() ^ Qt::FramelessWindowHint);
After constructing Q3DBars, you can set the data window by changing the range on the row and column axes. It is not mandatory, as data window will default to showing all of the data in the series. If the amount of data is large, it is usually preferable to show just a portion of it. For the example, let's set the data window to show first five rows and columns:
bars.rowAxis()->setRange(0, 4); bars.columnAxis()->setRange(0, 4);
Now Q3DBars is ready to receive data to be rendered. Create a series with one row of 5 values:
QBar3DSeries *series = new QBar3DSeries; QBarDataRow *data = new QBarDataRow; *data << 1.0f << 3.0f << 7.5f << 5.0f << 2.2f; series->dataProxy()->addRow(data); bars.addSeries(series);
Note: We set the data window to 5 x 5, but we are adding only one row of data. This is ok, the rest of the rows will just be blank.
Finally you will need to set it visible:
bars.show();
The complete code needed to create and display this graph is:
#include <QtDataVisualization> int main(int argc, char **argv) { qputenv("QSG_RHI_BACKEND", "opengl"); QGuiApplication app(argc, argv); Q3DBars bars; bars.setFlags(bars.flags() ^ Qt::FramelessWindowHint); bars.rowAxis()->setRange(0, 4); bars.columnAxis()->setRange(0, 4); QBar3DSeries *series = new QBar3DSeries; QBarDataRow *data = new QBarDataRow; *data << 1.0f << 3.0f << 7.5f << 5.0f << 2.2f; series->dataProxy()->addRow(data); bars.addSeries(series); bars.show(); return app.exec(); }
And this is what those few lines of code produce:
The scene can be rotated, zoomed into, and a bar can be selected to view its value, but no other interaction is included in this minimal code example. You can learn more by familiarizing yourself with the examples provided, like the Bar Graph.
See also Q3DScatter, Q3DSurface, and Qt Data Visualization C++ Classes.
Property Documentation
[since 6.3]
barSeriesMargin : QSizeF
Margin between series columns in X and Z dimensions. Sensible values are on the range [0,1).
Preset to (0.0, 0.0)
by default. This property enables showing bars from different series side by side, but with space between columns.
This property was introduced in Qt 6.3.
Access functions:
QSizeF | barSeriesMargin() const |
void | setBarSeriesMargin() |
Notifier signal:
void | barSeriesMarginChanged() |
See also barSpacing.
barSpacing : QSizeF
Bar spacing in the X and Z dimensions.
Preset to (1.0, 1.0)
by default. Spacing is affected by the barSpacingRelative property.
Access functions:
QSizeF | barSpacing() const |
void | setBarSpacing() |
Notifier signal:
void | barSpacingChanged() |
See also barSpacingRelative, multiSeriesUniform, and barSeriesMargin.
barSpacingRelative : bool
This property holds whether spacing is absolute or relative to bar thickness.
If it is 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
.
Access functions:
bool | isBarSpacingRelative() const |
void | setBarSpacingRelative() |
Notifier signal:
void | barSpacingRelativeChanged() |
barThickness : float
This property holds 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. Preset to 1.0
by default.
Access functions:
float | barThickness() const |
void | setBarThickness() |
Notifier signal:
void | barThicknessChanged() |
columnAxis : QCategory3DAxis*
This property holds the axis attached to the active column.
Access functions:
QCategory3DAxis * | columnAxis() const |
void | setColumnAxis() |
Notifier signal:
void | columnAxisChanged() |
floorLevel : float
This property holds 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.
Access functions:
float | floorLevel() const |
void | setFloorLevel() |
Notifier signal:
void | floorLevelChanged() |
multiSeriesUniform : bool
This property holds 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.
Access functions:
bool | isMultiSeriesUniform() const |
void | setMultiSeriesUniform() |
Notifier signal:
void | multiSeriesUniformChanged() |
primarySeries : QBar3DSeries*
This property holds the primary series of the graph.
Access functions:
QBar3DSeries * | primarySeries() const |
void | setPrimarySeries() |
Notifier signal:
void | primarySeriesChanged() |
rowAxis : QCategory3DAxis*
This property holds the axis attached to the active row.
Access functions:
QCategory3DAxis * | rowAxis() const |
void | setRowAxis() |
Notifier signal:
void | rowAxisChanged() |
[read-only]
selectedSeries : QBar3DSeries* const
This property holds the selected series or a null value.
If selectionMode has the SelectionMultiSeries
flag set, this property holds the series that owns the selected bar.
Access functions:
QBar3DSeries * | selectedSeries() const |
Notifier signal:
void | selectedSeriesChanged() |
valueAxis : QValue3DAxis*
Sets the active value axis (the Y-axis) to axis. Implicitly calls addAxis() to transfer the ownership of axis to this graph.
If axis is null, a temporary default axis with no labels and an automatically adjusting range is created. This temporary axis is destroyed if another axis is set explicitly to the same orientation.
Access functions:
QValue3DAxis * | valueAxis() const |
void | setValueAxis() |
Notifier signal:
void | valueAxisChanged() |
See also addAxis() and releaseAxis().
Member Function Documentation
[virtual]
Q3DBars::~Q3DBars()
Destroys the 3D bar graph.
QList<QAbstract3DAxis *> Q3DBars::axes() const
Returns the list of all added axes.
See also addAxis().
QList<QBar3DSeries *> Q3DBars::seriesList() const
Returns the list of series added to this graph.
See also QAbstract3DGraph::hasSeries().