demo D193
Statistics without a panel
Every figure available to your own interface, as an object
grid.statistics.*
Loading a live grid…
The configuration
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.28.0/lattice-grid.min.css">
<script type="module">
import { defineLatticeGrid } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.28.0/modules/webcomponent.esm.js';
defineLatticeGrid();
</script>
<lattice-grid row-key="id" style="display: block; height: 460px"></lattice-grid>
<pre id="out" style="margin-top: 12px"></pre>
<script type="module">
const el = document.querySelector('lattice-grid');
el.config = {
toolPanel: { side: 'left', panels: ['filters', 'columns'] },
columns: [
{ field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
{ field: 'desk', title: 'Desk', filter: { type: 'set' } },
{ field: 'price', title: 'Price', type: 'number' },
{ field: 'bid', title: 'Bid', type: 'number' },
{ field: 'volume', title: 'Volume', type: 'number' },
{ field: 'notional', title: 'Notional', type: 'number',
format: { style: 'currency', currency: 'USD' }, total: 'sum' },
],
};
el.rows = rows; // trading book records
// el.grid is the live grid inside the element. The statistics API reads the
// filtered rows, so every figure follows the filters. Recompute on change.
const grid = el.grid;
const out = document.getElementById('out');
const report = () => {
out.textContent = JSON.stringify({
profile: grid.statistics.profile('notional'),
correlation: grid.statistics.correlation('price', 'bid'),
regression: grid.statistics.regression('price', 'bid'),
spearman: grid.statistics.spearman('price', 'bid'),
}, null, 2);
};
grid.on('filter:changed', report); // every figure follows the filters
report();
</script>