▦K2 Advanced GridsDeveloper Portal / 0.23
Documentation / Data presentation

Data bars & color scales

Turn numeric cells into visual comparisons without changing their underlying values. Use progress bars, diverging bars and two- or three-color scales in the same Purchase Order Register.

Prepare the register

Use the 17-column View from earlier lessons. Show these nine columns: Order Number, Vendor Name, Department, Order Amount, Budget Variance, Delivery Progress, Status, Is Approved, Is Urgent. Clear filters, unpin columns and use 10 rows per page. For a clean comparison the primary downloads disable Conditional Formatting and use Boolean icons, matching the Runtime captures. Previous filtering, paging, summary, scrolling and column management remain available.

Download progress configuration ↓
Required after saving a configuration file

Replace REPLACE_WITH_YOUR_AREAITEMID with your own ID (see Grid Discovery). Save the chosen file under the name loaded by your Data Label, increment configVersion and reload the form. Saved grid preferences may override layout defaults; use Reset grid preferences if necessary. Engine version stays unchanged.

Fixed progress bars

Delivery Progress uses the fixed range 0–100. The bar fills the cell in proportion to completion; zero has no visible fill and 100 fills the cell.

K2AdvancedGridsConfig.defaults.dataVisualization = {
    "enabled": true,
    "scope": "loaded",
    "columns": {
        "Delivery Progress": {
            "mode": "bar",
            "min": 0,
            "max": 100,
            "positiveColor": "#26845B",
            "opacity": 0.3,
            "showZeroAxis": false
        }
    }
};
K2AdvancedGrids.instance.refresh();
Fixed 0–100 delivery progress
Figure 69 · Fixed 0–100 delivery progress · Actual K2 Runtime capture

Automatic data bars

Order Amount uses the loaded numeric extent with zero included for automatic bar bounds. Sort descending to see the largest amount, 239,078.00 SAR, fill the cell.

K2AdvancedGridsConfig.defaults.dataVisualization.columns["Order Amount"] = {
    "mode": "bar",
    "scope": "loaded",
    "positiveColor": "#8439A6",
    "opacity": 0.25,
    "showZeroAxis": false
};
K2AdvancedGrids.instance.refresh();
Automatic amount bars
Figure 70 · Automatic amount bars · Actual K2 Runtime capture
Amount sorted descending
Figure 71 · Amount sorted descending · Actual K2 Runtime capture

Diverging data bars

Negative amounts extend toward the start from zero, positive amounts toward the end. A zero axis appears only when the range straddles zero. Automatic bounds may be asymmetric. A fixed −2000 to +2000 range places zero in the center; values beyond the bounds are visually clamped, not changed.

K2AdvancedGridsConfig.defaults.dataVisualization.columns["Budget Variance"] = {
    "mode": "bar",
    "scope": "loaded",
    "positiveColor": "#26845B",
    "negativeColor": "#DC2626",
    "opacity": 0.3,
    "showZeroAxis": true
};
K2AdvancedGrids.instance.refresh();
Download automatic bars configuration ↓
Automatic diverging bars
Figure 72 · Automatic diverging bars · Actual K2 Runtime capture
K2AdvancedGridsConfig.defaults.dataVisualization.columns["Budget Variance"] = {
    "mode": "bar",
    "scope": "loaded",
    "positiveColor": "#26845B",
    "negativeColor": "#DC2626",
    "opacity": 0.3,
    "showZeroAxis": true,
    "min": -2000,
    "max": 2000
};
K2AdvancedGrids.instance.refresh();
Download fixed range configuration ↓
Fixed symmetric range
Figure 73 · Fixed symmetric range · Actual K2 Runtime capture

Loaded versus filtered range

Filter Department = Procurement (32 matching out of 250 loaded). Switch only Order Amount scope. The maximum for Procurement (238,449) is very close to the loaded maximum (239,078), so the two screenshots differ only slightly. Fixed bounds are unaffected by scope.

Procurement — loaded range
Figure 74 · Procurement — loaded range · Actual K2 Runtime capture
K2AdvancedGridsConfig.defaults.dataVisualization.columns['Order Amount'].scope = 'filtered';
K2AdvancedGrids.instance.refresh();
Procurement — filtered range
Figure 75 · Procurement — filtered range · Actual K2 Runtime capture

Inspect the actual calculated bounds rather than relying only on the pixels. For a more visible difference, filter Order Amount to a lower range, then compare the same rows with both scopes. Clear filters and restore loaded scope afterwards.

const id = 'REPLACE_WITH_YOUR_AREAITEMID';
const grid = K2AdvancedGrids.instance.inspect().find(g => g.id === id);
console.table(grid?.dataVisualization || []);
Offline scope playground

Illustrative subset, not a live K2 grid. The maximum of the filtered example is deliberately much smaller.

Three-color scales

Clear filters. Budget Variance uses red, yellow and green with fixed symmetric bounds. The middle color corresponds to the midpoint of the range, not the median or necessarily zero.

K2AdvancedGridsConfig.defaults.dataVisualization.columns["Budget Variance"] = {
    "mode": "scale",
    "scope": "loaded",
    "min": -2000,
    "max": 2000,
    "minColor": "#DC2626",
    "midColor": "#FACC15",
    "maxColor": "#26845B",
    "opacity": 0.65
};
K2AdvancedGrids.instance.refresh();
Three-color budget variance scale
Figure 76 · Three-color budget variance scale · Actual K2 Runtime capture

Two-color scales

Set midColor to false to interpolate directly between the minimum and maximum colors. Sort Order Number descending to show contrasting values.

K2AdvancedGridsConfig.defaults.dataVisualization.columns["Order Amount"] = {
    "mode": "scale",
    "scope": "loaded",
    "minColor": "#F3E8FF",
    "midColor": false,
    "maxColor": "#8439A6",
    "opacity": 0.65
};
K2AdvancedGrids.instance.refresh();
Download color scales configuration ↓
Two-color amount scale with three-color variance
Figure 77 · Two-color amount scale with three-color variance · Actual K2 Runtime capture

Opacity and interactive playground

Choose an intensity that keeps numbers readable. The following offline simulation illustrates the color and opacity settings; it does not execute the K2 engine.

Combined visualization

Restore Order Number ascending and use fixed progress bars, automatic amount bars and a softer three-color variance scale together. This reproduces the demonstrated visualization with Boolean icons. The optional extended configuration restores the previous status badges and conditional rules; their interaction with visualizations has not been independently verified in this lesson.

K2AdvancedGridsConfig.defaults.dataVisualization = {
    "enabled": true,
    "scope": "loaded",
    "columns": {
        "Delivery Progress": {
            "mode": "bar",
            "min": 0,
            "max": 100,
            "positiveColor": "#26845B",
            "opacity": 0.3,
            "showZeroAxis": false
        },
        "Order Amount": {
            "mode": "bar",
            "scope": "loaded",
            "positiveColor": "#8439A6",
            "opacity": 0.25,
            "showZeroAxis": false
        },
        "Budget Variance": {
            "mode": "scale",
            "scope": "loaded",
            "min": -2000,
            "max": 2000,
            "minColor": "#DC2626",
            "midColor": "#FACC15",
            "maxColor": "#26845B",
            "opacity": 0.4
        }
    }
};
K2AdvancedGrids.instance.refresh();
Download combined visualization ↓ Download extended formatting example (not yet verified) ↓
Combined bars and scale
Figure 78 · Combined bars and scale · Actual K2 Runtime capture

Configuration reference

ParameterBehavior
enabledModule must be true; per-column false skips that column.
columnsMap of column keys, names or titles; numeric types only.
modebar or scale.
scopeloaded (default) or filtered; per-column setting overrides module.
min / maxOptional numeric bounds; missing bar bounds include zero. Scale bounds use data extent. Equal bounds produce a midpoint scale and no bar.
positiveColor / negativeColorColors for positive and negative bars.
showZeroAxisDefaults to on for ranges crossing zero.
opacity0–1; clamped; default 0.25.
minColor / midColor / maxColorScale colors; midColor:false selects two colors.

Benefits and limitations

Compared with the baseline, users can identify large orders, delivery progress and variance patterns at a glance. This is client-side rendering over loaded numeric records, not server aggregation or a query. Blank or nonnumeric cells are skipped. The engine uses CSS gradients and color-mix(); bars and scales are intentionally suppressed while a row is hovered or selected to preserve native selection feedback. Cell merging excludes cells with Data Visualization. Fixed range clamping and equal bounds are source-derived behaviors, not separately demonstrated here. Use the diagnostic command above to confirm scope differences. The extended formatting example requires runtime verification.

Enlarged screenshot