demo D193
Statistics without a panel in Vue
Every figure available to your own interface, as an object
grid.statistics.*
This grid exposes every figure it computes as a plain object, for your own interface with no panel involved. It lets you take the statistics into a custom dashboard or export, so the numbers are available wherever you need them.
This is the Vue 3 version. A createLatticeGrid component takes the configuration through v-bind, and reactive data flows straight into the grid, so it updates the way the rest of your Vue app does.
The configuration
<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.108.0/lattice-grid.min.css">
<style>
#grid > div { height: 460px; }
#out { margin-top: 12px; }
</style>
<div id="app"></div>
<script type="module">
import * as Vue from 'https://esm.sh/vue@3/dist/vue.esm-browser.prod.js';
import { createGrid } from 'https://cdn.latticegrid.dev/lattice-grid@1.108.0/lattice-grid.esm.min.js';
import createLatticeGrid from 'https://cdn.latticegrid.dev/lattice-grid@1.108.0/modules/vue.esm.min.js';
const LatticeGrid = createLatticeGrid({ vue: Vue, createGrid });
Vue.createApp({
components: { LatticeGrid },
data() {
return {
config: {
rowKey: 'id',
columnDefaults: { filter: true },
toolPanel: { side: 'left', panels: ['filters', 'columns'] },
columns: [
{ field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
{ field: 'desk', title: 'Desk', filter: { type: 'set' } },
{ field: 'region', title: 'Region', filter: { type: 'set' } },
{ field: 'price', title: 'Price', type: 'number', format: { decimals: 4 } },
{ field: 'bid', title: 'Bid', type: 'number', format: { decimals: 4 } },
{ field: 'volume', title: 'Volume', type: 'number', format: { notation: 'compact' } },
{ field: 'notional', title: 'Notional', type: 'number',
format: { style: 'currency', currency: 'USD', decimals: 2 }, total: 'sum' },
],
rows, // trading book: symbol, desk, region, price, bid, volume, notional
},
};
},
mounted() {
// Read the figures once the grid is live, then on every filter change.
this.report();
},
methods: {
// The statistics API reads whole columns over the filtered rows: a profile,
// two-column relationships and the rank-based Spearman, all into a panel
// of your own.
report() {
const grid = this.$refs.grid.grid();
document.getElementById('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'),
weightedMedian: grid.statistics.weightedQuantile('price', 'volume', 0.5),
}, null, 2);
},
},
template: `
<div id="grid"><lattice-grid ref="grid" v-bind="config" @filter-changed="report" /></div>
<pre id="out"></pre>
`,
}).mount('#app');
</script>