Skip to content

3D Bar Chart

WASM Powered
💎Advanced
Star
👑Pioneer

TuiBar3D is a 3D visualization chart component with high-fidelity material texture, built using dynamic SVG technology.

Unlike ordinary pseudo-3D charts, Bar3D simulates the physical effects of a translucent glass shell and internal liquid filling. It utilizes advanced CSS3 features to build visual effects with perspective depth, light refraction, and dynamic liquid levels without introducing a heavy WebGL engine.

TuiBar3D is one of the 7 advanced components in the library and requires authorization to use.

Core Features

  • Dual Shapes: Supports two geometric forms: Cylinder and Cube.
  • Liquid Level Simulation: The interior of the column presents a liquid filling effect. The liquid height changes with data, accompanied by floating light and shadow effects.
  • Smart Thresholds: Supports configuration of multi-level thresholds. It automatically switches the bar color state (e.g., Danger, Warning, Normal, Success) based on the numerical value.
  • Scene Components: Optional configuration for Base and Back Track to enhance the sense of spatial positioning.
  • Queue Animation: Cooperates with TuiBar3DGroup to achieve delayed sequence playback for multiple sets of data.

Basic Usage

Bar3D is a highly adaptive component; its height is completely determined by the parent container.

html
<template>
  <div style="height: 300px; width: 100px;">
    <TuiBar3D 
      label="Visits"
      :value="75"
      :maxValue="100"
      unit="Times"
      shape="cylinder" 
    />
  </div>
</template>

Advanced Features

Thresholds & Status

The component supports automatically changing the color state based on numerical values.

  • Manual Status: Forcibly specify via the status prop (normal, success, warning, danger, critical, emphasis).
  • Automatic Thresholds: Configured via the thresholds object. When value reaches the set value, the corresponding state color is automatically applied.
javascript
const myThresholds = {
  danger: 0,    // 0-59 displays Red (danger)
  warning: 60,  // 60-79 displays Orange (warning)
  success: 80   // >=80 displays Green (success)
}
html
<TuiBar3D :value="85" :thresholds="myThresholds" />

3D Scene Configuration

Enhance the stereoscopic effect by adjusting the viewing distance and auxiliary components.

  • viewDeep: View Depth. The larger the value, the more exaggerated the perspective (stronger top-down view); the smaller the value, the closer it is to a flat plane.
  • showBase: Displays the bottom base.
  • showTrack: Displays the translucent back track.
  • gap: The spacing between the bar and its back track. Increasing this value enhances the sense of suspension.

Queue Display (Group)

Use the helper component TuiBar3DGroup to quickly render a group of bar charts and automatically handle Staggered Entrance Animations (delayed playback).

html
<template>
  <div style="height: 300px; display: flex;">
    <TuiBar3DGroup 
      :items="[
        { label: 'Area A', value: 45 },
        { label: 'Area B', value: 80 },
        { label: 'Area C', value: 30 }
      ]"
      :progress3DBarConfig="{
         shape: 'cube',
         showBase: true,
         aniDelay: 500 // Unified animation delay configuration
      }" 
    />
  </div>
</template>

API Reference

Props

Data Configuration

Property NameTypeDefaultDescription
labelStringRequiredThe title label displayed at the bottom.
valueNumber0Current value.
maxValueNumbernullMaximum value (used to calculate liquid level percentage). Defaults to 100 if not specified.
unitString''Numerical unit.
precisionNumber0Display precision (number of decimal places).
displayValueString'auto'Value display mode: 'auto' (Automatic), 'none' (Hidden), 'all' (Show Value/Max), 'allReverse' (Show Value/Max with line break).
mainValuePositionString'auto'Main value display position. 'auto' (Follows liquid level), 'top' (Fixed at top).

Appearance & Shape

Property NameTypeDefaultDescription
shapeString'cylinder'Bar shape. Options: 'cylinder', 'cube'.
statusStringnullForced status color: 'normal', 'success', 'danger', 'warning', 'emphasis', 'critical'.
thresholdsObjectnullThreshold configuration object. Keys are status names, values are trigger thresholds.
barColorStringnullCustom bar color (accepts CSS color values).
barColorRatioNumber15Bar gradient difference coefficient (controls the intensity of stereoscopic lighting).
barBlurNumber0.7Bar blurriness (frosted glass effect).
barOpacityNumber0.9Bar opacity.

3D Scene & Auxiliaries

Property NameTypeDefaultDescription
viewDeepNumber153D View Depth (0-50).
showTrackBooleantrueWhether to show the back track.
trackOpacityNumber0.5Track opacity.
gapNumber30Spacing between the bar and the track.
showBaseBooleanfalseWhether to show the base.
baseSpacingNumber20Base margin size.
baseColorWeakenedBooleanfalseWhether to weaken the base color.

Animation & Control

Property NameTypeDefaultDescription
durationNumber1000Animation duration (ms).
aniDelayNumber2000Entrance animation delay (ms).
resizeObserverString'global'Dimension listening strategy: 'self', 'global', 'none'.
initHoldBooleanfalseWhether to keep still (no animation) on initialization.

Events

Event NameDescription
initedTriggered when component initialization and entrance animation are complete.

Expose

Property NameTypeDescription
initedBooleanWhether the current component has completed initialization.

Visual

The visual effects of Bar3D are controlled by a set of fine-tuned SVG gradient variables. The component splits the bar, base, and track into multiple illuminated surfaces internally and assigns different CSS variables to them to simulate real lighting relationships.

You can override the following variables to adjust the color of each part:

Bar

The bar is the visual subject. Its color is automatically determined by the status or thresholds, but its lighting hierarchy is controlled by the following variables:

  • --tui-bar3d-bargrad-A: Highlight Surface Color. Usually used for the side or top surface that receives the strongest light.
  • --tui-bar3d-bargrad-B: Mid-tone/Transition Color. Used for the main transition area of the bar or Side A of the cube.
  • --tui-bar3d-bargrad-C: Backlight/Shadow Color. Used for the shadow side of the bar or Side B of the cube.
  • --tui-bar3d-shinegrad-A / B: Glass Highlight Color. Used to simulate the specular reflection of the shell (usually translucent white).

Base

When showBase is enabled, the color of the base is controlled by the following variables:

  • Normal State:

    • --tui-bar3d-basgrad-A: Base illuminated surface.
    • --tui-bar3d-basgrad-B: Base backlight/transition surface.
  • Weakened State (is-weakened):

    • When baseColorWeakened is enabled, the base is forced to use the Track's color variables, thereby visually receding to a secondary position to highlight the data bar.

Track

When showTrack is enabled, the color of the translucent back track:

  • --tui-bar3d-trkgrad-A: Track illuminated surface.
  • --tui-bar3d-trkgrad-B: Track backlight surface.

Gradient Mapping Logic (Example: Cube)

To give the Cube a stereoscopic feel, the component uses a "Dual-Face Shading" strategy:

  • Side A (cubeSA): Maps to the gradient bargrad-B -> bargrad-A (Light to Dark transition).
  • Side B (cubeSB): Maps to the gradient bargrad-B -> bargrad-C (Neutral to Shadow transition).

This differentiated mapping ensures that even with monochromatic data, it presents a clear, sharp-edged perception.

Released under the MIT License.