demo D173
Brushing a time range
Drag a range on the chart and the grid narrows to it
brush: true
Loading a live grid…
The configuration
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/lattice-grid.min.css">
<div id="app"></div>
<script type="module">
import React from 'https://esm.sh/react@18';
import { createRoot } from 'https://esm.sh/react-dom@18/client';
import { createGrid } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/lattice-grid.esm.min.js';
import createLatticeGrid from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/modules/react.esm.min.js';
import { createChart } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/modules/charts.esm.min.js';
const LatticeGrid = createLatticeGrid({ React, createGrid });
const 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' } },
];
const rows = [/* one row a day: date, price, volume */];
function App() {
const gridRef = React.useRef(null);
React.useEffect(() => {
const grid = gridRef.current.grid;
// brush: true lets you drag a range across the chart, and the grid narrows
// to those days. The chart reads the live grid through the ref, so both
// views move on one gesture.
createChart({ grid, container: '#chart', type: 'line', x: 'date', y: 'price', brush: true,
title: 'Price over time (brush to filter)' });
}, []);
return (
<>
<div id="chart" style={{ height: '300px' }} />
<LatticeGrid
ref={gridRef}
rowKey="id"
columns={columns}
rows={rows}
style={{ height: '320px', marginTop: '14px' }}
/>
</>
);
}
createRoot(document.getElementById('app')).render(<App />);
</script>