demo D205
Density over a histogram
A kernel density estimate over the bars, so binning and data separate
curve: true, buckets
Loading a live grid…
The configuration
import * as ng from '@angular/core';
import { Component, ViewChild, AfterViewInit } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
import createLatticeGrid from '@toclocoinc/lattice-grid/modules/angular';
const { LatticeGridComponent } = createLatticeGrid({ ng, createGrid });
const columns = [
{ field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
{ field: 'desk', title: 'Desk', filter: { type: 'set' } },
{ field: 'price', title: 'Price', type: 'number', format: { decimals: 4 } },
{ field: 'volume', title: 'Volume', type: 'number', format: { notation: 'compact' } },
];
const rows = [/* trading records, one per instrument */];
@Component({
selector: 'app-root',
standalone: true,
imports: [LatticeGridComponent],
template:
'<div id="chart" style="height:340px"></div>' +
'<lattice-grid [config]="grid" style="display:block;height:320px;margin-top:14px"></lattice-grid>',
})
export class AppComponent implements AfterViewInit {
@ViewChild(LatticeGridComponent) gridRef!: LatticeGridComponent;
grid = {
rowKey: 'id',
columns: columns,
rows: rows,
};
ngAfterViewInit() {
const grid = this.gridRef.grid;
// The bars depend on where the bin edges fall; the density curve has no
// edges, so laying one over the other separates the shape of the data from
// the choice of buckets. The chart reads the live grid through the ref.
createChart({ grid, container: '#chart', type: 'histogram', y: 'price',
buckets: 20, curve: true, title: 'Price, with a density curve' });
}
}
bootstrapApplication(AppComponent);