Trade Area Sales in 3D
A 10×10 grid of 100 columns sets height by sales and color by year-over-year change from -15% to +25%, with a slider for the height multiplier.
Business context
Retail operations and regional management use a column field to compare trade-area sales and year-over-year change side by side and quickly find areas needing intervention, and to report regional performance to headquarters. Data comes from store POS aggregation, trade-area partitioning and prior-year baselines; a city typically has dozens to a couple hundred trade areas, updated monthly or quarterly in a low-frequency but high-attention analytical view.
Sales are first normalized for currency and tax treatment, trade-area centroids and grid spacing are fixed, and column height follows only the value and a shared multiplier with no runtime normalization. ColumnLayer is chosen because each trade area is an independent object needing per-column picking and a stable visual unit; the cylindrical geometry reads clearly at oblique angles, and gaps between columns keep them from merging into a wall.
If the height multiplier is not fixed, cross-period comparison fails: stretching to each period's maximum makes the tallest column identical every period and visually erases growth. Color also encodes year-over-year change rather than absolute sales, so a deep blue column does not mean poor sales; it may be a high base with slowing growth, and the two dimensions must be read separately.
How it works
The 100 trade areas form a 10×10 grid with longitude steps of 0.01231° and latitude steps of 0.00950°, about 1050 m; a 420 m column radius gives an 840 m diameter, 0.8 of the spacing, leaving 210 m gaps so columns do not merge into a wall at oblique angles. Sales follow a power distribution from 0.04 to 0.32 billion yuan, getElevation returns the value in hundred-million yuan, elevationScale defaults to 480, and the tallest column reaches about 1536 m.
Color is banded by year-over-year change: below -8% deep blue, -8% to 0 light blue, 0 to 8% off-white, 8% to 15% amber, above 15% orange-red, so decline and growth separate within one family. The height multiplier is never auto-normalized; only a fixed 480 puts two periods on one ruler, whereas stretching to each period's maximum makes the tallest column identical every period and visually erases growth.
| Configuration | What it does |
|---|---|
| radius 420 / spacing 1050 | Diameter-to-spacing ratio near 0.8 keeps columns separated |
| diskResolution: 16 | 16 edges per column, smooth enough up close |
| elevationScale 100–900 | A single height multiplier applied live by the slider |
| getFillColor five steps | Year-over-year palette, cool for negative and warm for positive |
Note. ColumnLayer has no elevationRange, so cross-period comparison relies on a fixed elevationScale; scaling heights to each period's maximum destroys comparability.
Source
<!--
示例:商圈销售额 3D 柱
要点:ColumnLayer 按销售额挤出、按同比增长着色,柱半径与网格间距保持 0.8 的比例
依赖:deck.gl 9.0 · jsDelivr CDN
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta name="robots" content="noindex,follow">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>商圈销售额 3D 柱</title>
<style>
html,body{height:100%;margin:0;background:#0d1117}
body{display:flex;flex-direction:column;overflow:hidden;
font:13px/1.6 -apple-system,"Segoe UI","PingFang SC",sans-serif;color:#e6e8ec}
.bar{position:relative;z-index:5;flex:0 0 auto;padding:8px 12px;background:#161b22;border-bottom:1px solid #252c36;
display:flex;gap:12px;align-items:center;font-size:12px;color:#8b93a1;flex-wrap:wrap}
.bar b{color:#58a6ff;font-weight:600}
.bar input[type=range]{width:150px;accent-color:#4f9ef8}
.bar button{font:inherit;font-size:12px;padding:3px 10px;border-radius:5px;cursor:pointer;
border:1px solid #303845;background:#1d2531;color:#c8d2e0}
.bar button:hover{background:#253040}
.bar button.on{background:#2c4a7a;border-color:#4f8ad6;color:#dfe9ff}
.bar .sep{width:1px;height:18px;background:#2a313c;margin:0 4px}
#cv{flex:1 1 auto;min-height:0;width:100%;display:block}
</style>
</head>
<body>
<div class="bar">
<span>商圈 <b id="n">100</b></span>
<span>总销售额 <b id="sum">—</b></span>
<span class="sep"></span>
<span>elevationScale</span>
<input id="sc" type="range" min="100" max="900" step="20" value="480">
<span><b id="scv">480</b></span>
<span class="sep"></span>
<button id="byYoy" class="on">按增长着色</button>
<button id="mono">单色</button>
</div>
<canvas id="cv"></canvas>
<script src="https://cdn.jsdelivr.net/npm/deck.gl@9.0.35/dist.min.js"></script>
<script>
(function () {
'use strict';
if (typeof deck === 'undefined') {
document.body.innerHTML =
'<div style="padding:24px;color:#ff8c74">deck.gl 加载失败,请检查能否访问 cdn.jsdelivr.net</div>';
return;
}
function rng(seed) {
var a = seed >>> 0;
return function () {
a = (a + 0x6D2B79F5) >>> 0;
var t = Math.imul(a ^ (a >>> 15), 1 | a);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
var rand = rng(60127);
var STEP_LNG = 0.01231;
var STEP_LAT = 0.00950;
var cells = [];
var total = 0;
for (var i = 0; i < 10; i++) {
for (var j = 0; j < 10; j++) {
var sales = 0.4 + 2.8 * Math.pow(rand(), 1.7);
var yoy = (rand() * 40 - 15) * (sales > 1.6 ? 0.6 : 1.1);
if (yoy > 25) yoy = 25;
if (yoy < -15) yoy = -15;
total += sales;
cells.push({
lng: 116.40 + (i - 4.5) * STEP_LNG,
lat: 39.92 + (j - 4.5) * STEP_LAT,
sales: sales,
yoy: yoy
});
}
}
function pos(d) { return [d.lng, d.lat]; }
function yoyColor(d) {
var v = d.yoy;
if (v < -8) return [86, 140, 220, 235];
if (v < 0) return [96, 176, 214, 235];
if (v < 8) return [214, 218, 210, 235];
if (v < 15) return [246, 188, 84, 240];
return [236, 88, 60, 245];
}
function monoColor() { return [86, 156, 214, 235]; }
var colored = true;
var elevationScale = 480;
function buildLayer() {
return new deck.ColumnLayer({
id: 'sales-columns',
data: cells,
getPosition: pos,
diskResolution: 16,
radius: 420,
extruded: true,
getElevation: function (d) { return d.sales; },
elevationScale: elevationScale,
getFillColor: colored ? yoyColor : monoColor,
material: { ambient: 0.5, diffuse: 0.74, shininess: 26 },
pickable: true
});
}
document.getElementById('sum').textContent = total.toFixed(1) + ' 亿元';
var deckgl = new deck.Deck({
canvas: 'cv',
width: '100%',
height: '100%',
initialViewState: {
longitude: 116.40,
latitude: 39.92,
zoom: 13.2,
pitch: 52,
bearing: -20
},
controller: true,
layers: [buildLayer()],
getTooltip: function (info) {
var o = info.object;
if (!o) return null;
return '销售额 ' + o.sales.toFixed(2) + ' 亿元 · 同比 ' +
(o.yoy >= 0 ? '+' : '') + o.yoy.toFixed(1) + '%';
}
});
document.getElementById('sc').addEventListener('input', function (e) {
elevationScale = Number(e.target.value);
document.getElementById('scv').textContent = elevationScale;
deckgl.setProps({ layers: [buildLayer()] });
});
document.getElementById('byYoy').addEventListener('click', function () {
colored = true;
document.getElementById('byYoy').classList.add('on');
document.getElementById('mono').classList.remove('on');
deckgl.setProps({ layers: [buildLayer()] });
});
document.getElementById('mono').addEventListener('click', function () {
colored = false;
document.getElementById('mono').classList.add('on');
document.getElementById('byYoy').classList.remove('on');
deckgl.setProps({ layers: [buildLayer()] });
});
window.__deck = deckgl;
})();
</script>
</body>
</html>