demo D173
Brushing a time range in Vue
Drag a range on the chart and the grid narrows to it
brush: true
This lets you drag a range across a time chart and narrows the grid to it. It gives a reader a quick way to focus on a period, selecting the window on the chart and reading the matching rows in the grid.
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.107.0/lattice-grid.min.css">
<style>
#chart { height: 300px; }
#grid { margin-top: 14px; }
#grid > div { height: 340px; }
</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.107.0/lattice-grid.esm.min.js';
import createLatticeGrid from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/vue.esm.min.js';
import { createChart } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/charts.esm.min.js';
const LatticeGrid = createLatticeGrid({ vue: Vue, createGrid });
Vue.createApp({
components: { LatticeGrid },
data() {
return {
config: {
rowKey: 'id',
columns: [
{ field: 'date', title: 'Date', type: 'dateString', layout: { pin: 'start', width: 150 } },
{ field: 'price', title: 'Price', type: 'number', format: { decimals: 2 } },
{ field: 'volume', title: 'Volume', type: 'number', format: { notation: 'compact' } },
],
rows, // one row a day: date, price, volume
},
};
},
mounted() {
// The component exposes the live grid via a template ref, which the chart draws from.
const grid = this.$refs.grid.grid();
// brush lets a reader drag a range across the chart to narrow the grid to those days.
createChart({ grid, container: '#chart', type: 'line', x: 'date', y: 'price', brush: true, title: 'Price over time (brush to filter)' });
},
template: `
<div id="chart"></div>
<div id="grid"><lattice-grid ref="grid" v-bind="config" /></div>
`,
}).mount('#app');
</script>