Q3DBars Class

The Q3DBars class provides methods for rendering 3D bar graphs. More...

Header: #include <Q3DBars>
qmake: QT += datavisualization
Since: QtDataVisualization 1.0
Inherits: QAbstract3DGraph

This class was introduced in QtDataVisualization 1.0.

Properties

Public Functions

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
void setBarSpacing(const QSizeF &spacing)
void setBarSpacingRelative(bool relative)
void setBarThickness(float thicknessRatio)
void setColumnAxis(QCategory3DAxis *axis)
void setFloorLevel(float level)
void setMultiSeriesUniform(bool uniform)
void setPrimarySeries(QBar3DSeries *series)
void setRowAxis(QCategory3DAxis *axis)
void setValueAxis(QValue3DAxis *axis)
QValue3DAxis *valueAxis() const

Signals

void barSpacingChanged(const QSizeF &spacing)
void barSpacingRelativeChanged(bool relative)
void barThicknessChanged(float thicknessRatio)
void columnAxisChanged(QCategory3DAxis *axis)
void floorLevelChanged(float level)
void multiSeriesUniformChanged(bool uniform)
void primarySeriesChanged(QBar3DSeries *series)
void rowAxisChanged(QCategory3DAxis *axis)
void selectedSeriesChanged(QBar3DSeries *series)
void valueAxisChanged(QValue3DAxis *axis)

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>

 using namespace QtDataVisualization;

 int main(int argc, char **argv)
 {
     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 Bars Example.

See also Q3DScatter, Q3DSurface, and Qt Data Visualization C++ Classes.

Property Documentation

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(const QSizeF &spacing)

Notifier signal:

void barSpacingChanged(const QSizeF &spacing)

See also barSpacingRelative and multiSeriesUniform.

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(bool relative)

Notifier signal:

void barSpacingRelativeChanged(bool relative)

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(float thicknessRatio)

Notifier signal:

void barThicknessChanged(float thicknessRatio)

columnAxis : QCategory3DAxis*

This property holds the axis attached to the active column.

Access functions:

QCategory3DAxis *columnAxis() const
void setColumnAxis(QCategory3DAxis *axis)

Notifier signal:

void columnAxisChanged(QCategory3DAxis *axis)

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(float level)

Notifier signal:

void floorLevelChanged(float level)

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(bool uniform)

Notifier signal:

void multiSeriesUniformChanged(bool uniform)

primarySeries : QBar3DSeries*

This property holds the primary series of the graph.

Access functions:

QBar3DSeries *primarySeries() const
void setPrimarySeries(QBar3DSeries *series)

Notifier signal:

void primarySeriesChanged(QBar3DSeries *series)

rowAxis : QCategory3DAxis*

This property holds the axis attached to the active row.

Access functions:

QCategory3DAxis *rowAxis() const
void setRowAxis(QCategory3DAxis *axis)

Notifier signal:

void rowAxisChanged(QCategory3DAxis *axis)

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(QBar3DSeries *series)

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(QValue3DAxis *axis)

Notifier signal:

void valueAxisChanged(QValue3DAxis *axis)

See also addAxis() and releaseAxis().