3D Bar Chart - Qwt3DBar¶
Qwt3DBar is a 3D plot item for drawing bar charts in 3D space. Each sample becomes an axis-aligned cuboid ("bar") whose height encodes a scalar value. It supports both 1D series of bars and 2D grids (3D histograms / "bar3"), with per-bar colormap coloring, lit flat shading, and wireframe/edge overlays.
For an overview of the 3D module see 3D Plot Introduction. Qwt3DBar is a Qwt3DPlotItem and follows the same attach/draw/hull contract as Qwt3DSurface.
Key Features¶
-
Two data shapes: 1D series (bars placed freely on the xy-plane) and 2D grid (3D histogram over an x/y domain)
-
Lit solid geometry: per-bar cuboids with flat per-face normals, responding to
Qwt3DPlot::enableLighting()(Blinn-Phong) -
Three styles:
Filled,FilledMesh(filled + edge lines),Wireframe -
Per-bar color: driven by a
Qwt3DColorfunctor (typically by height z), with colormap presets available throughQwt3DColorMapColor -
Configurable geometry: baseline and auto footprint (bar width/depth = 80% of spacing by default)
-
Theme integration: picked up automatically by
Qwt3DTheme::applyToItem()
Basic Concepts¶
Data Shapes¶
| Shape | setSamples overload |
Use case |
|---|---|---|
| 1D series | setSamples(QVector<QwtPoint3D>) or (x, heights) |
Bars along an axis / scattered bars |
| 2D grid | setSamples(double** z, cols, rows, minX, maxX, minY, maxY) or (Qwt3DFunctionData) |
3D histogram (bar3) |
For the 1D series, (x, y) is the bar footprint center and z is the height. For the 2D grid, z[i][j] is the height at grid node (xi, yj).
Rendering Styles¶
| Style | Description |
|---|---|
Qwt3DBar::Filled |
Filled bars, no edges |
Qwt3DBar::FilledMesh |
Filled bars + separately colored edge lines (default) |
Qwt3DBar::Wireframe |
Edge lines only |
Architecture¶
classDiagram
class Qwt3DPlotItem {
<<abstract>>
+attach(plot)
+draw()*
+hull()*
+itemChanged()
}
class Qwt3DBar {
+setSamples()
+setBarStyle()
+setDataColor()
+setBarWidth()/setBarDepth()
+setBaseline()
+invalidateColors()
}
Qwt3DPlotItem <|-- Qwt3DBar
Qwt3DBar reuses the lit surface shader (:/shaders/surface.vert/frag); each bar is emitted as 6 flat-normal faces (24 vertices, 36 triangle indices). It owns its VBO/VAO/EBO and a Qwt3DColor functor, exactly like Qwt3DSurface.
Usage¶
The 3D bar chart example is located at: examples/3D/bar3D.
1. 2D Grid Bar Chart (3D histogram)¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
2. 1D Series of Bars¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
3. Bar Geometry: Footprint and Baseline¶
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
4. Coloring¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
5. Switching Styles¶
1 2 3 4 5 6 7 8 9 | |
6. Theme & Coordinate System¶
1 2 3 4 5 6 7 8 9 | |
Core Methods Summary¶
| Method | Description |
|---|---|
setSamples(...) |
Load bar data (1D or 2D grid, see Data Shapes) |
setBarWidth(w) / setBarDepth(d) |
Bar footprint (<= 0 = auto, 80% of spacing) |
setBaseline(z) |
Bar bottom z (default 0) |
setBarStyle(BarStyle) |
Filled / FilledMesh / Wireframe |
setDataColor(Qwt3DColor*) |
Per-bar color functor (takes ownership) |
dataColor() |
Get the color functor |
setMeshColor(RGBA) / setMeshLineWidth(double) |
Edge line appearance |
invalidateColors() |
Rebuild VBO colors after mutating the functor in place |
hull() |
Bounding box (used by the plot to frame the coordinate system) |
draw() / populateLegendColors() |
Qwt3DPlotItem interface |
Tip
Keep grids modest (a few thousand bars); each bar emits 24 vertices.
Use
FilledMeshwith a semi-transparent mesh color for visible edges without clutter.
enableLighting(true)makes flat-shaded bars easier to read in 3D.For anisotropic data, call
plot->coordinates()->setTicLengthScale(...)so axis ticks stay proportional.Example β Related Examples
3D bar chart:
examples/3D/bar3DLive stacked traces (spectra) instead of bars: 3D Waterfall,
examples/3D/waterfall3D