Data bars
A data bar draws a left-anchored horizontal bar behind each cell whose length is the value’s fraction
of the column domain — an at-a-glance magnitude comparison down a column. It renders as a CSS
linear-gradient background (no extra DOM), and like every cell visual it is presentation only: the
engine ships raw numerics, the frontend just paints.
from dash_tensor_grid import TensorGrid, build_grid
payload = build_grid(sales, { "rows": ["region", "country"], "measures": {"revenue": "sum", "qty": "sum"}, "formats": {"revenue": "currency:USD", "qty": "number:0"}, "conditional_formats": { "qty": {"type": "dataBar", "color": "#4c8bf5"}, # Diverging on zero: {"type": "dataBar", "color": "#2f9e44", # "negativeColor": "#e03131", "origin": 0} },})TensorGrid(id="grid", row_data=payload["row_data"], column_defs=payload["column_defs"])<TensorGrid data={data} rows={['region', 'country']} measures={{ revenue: 'sum', qty: 'sum' }} formats={{ revenue: '$0,0', qty: '0,0' }} dataBars={{ qty: { color: '#4c8bf5', domainMin: 0, domainMax: 12 } }}/>;<TensorGrid :data="data" :rows="['region', 'country']" :measures="{ revenue: 'sum', qty: 'sum' }" :formats="{ revenue: '$0,0', qty: '0,0' }" :data-bars="{ qty: { color: '#4c8bf5', domainMin: 0, domainMax: 12 } }"/>mountTensorGrid(el, { data, rows: ['region', 'country'], measures: { revenue: 'sum', qty: 'sum' }, formats: { revenue: '$0,0', qty: '0,0' }, dataBars: { qty: { color: '#4c8bf5', domainMin: 0, domainMax: 12 } },});Options
Section titled “Options”color— the bar fill (any CSS color). For a diverging bar it is the above-origin (positive) side.origin— the value the bar diverges from. Withoriginset, values above it paint rightward incolorand values below paint leftward innegativeColor— the standard variance / profit-loss look (origin: 0). A value exactly at the origin draws no bar. Omitoriginfor a classic zero-based left-anchored bar.negativeColor— the below-origin fill for a diverging bar (defaults tocolor).domainMin/domainMax— fix the bar’s domain.domainMindefaults to0(a zero-based bar);domainMaxdefaults to the column’s maximum. For a diverging bar give the domain room on both sides (e.g.domainMin: -100, domainMax: 100, origin: 0).- For a background heatmap instead of a bar, see color scales; background precedence is an explicit style rule background, then the data bar, then the color scale.