Lattice Grid Buy a licence

demo D228

Confidence intervals, charted

The mean lead time of each supplier with its 95% interval as a whisker, and a tile that narrows as you filter

grid.statistics.interval(col) · chart error: true

Building…
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, createStat } 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 });

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [LatticeGridComponent],
  template:
    '<div #chart style="height:250px"></div>' +
    '<div #tiles style="display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin:14px 0"></div>' +
    '<lattice-grid [config]="grid" style="display:block;height:340px"></lattice-grid>',
})
export class AppComponent implements AfterViewInit {
  @ViewChild('chart') chartEl!: ng.ElementRef<HTMLElement>;
  @ViewChild('tiles') tilesEl!: ng.ElementRef<HTMLElement>;
  @ViewChild(LatticeGridComponent) gridRef!: LatticeGridComponent;

  grid = {
    rowKey: 'id',
    toolPanel: { side: 'left', panels: ['filters', 'columns', 'statistics'] },
    columns: [
      { field: 'supplier', title: 'Supplier', filter: { type: 'set' } },
      { field: 'days', title: 'Lead time', type: 'number', format: { suffix: ' d', maximumFractionDigits: 1 }, total: 'avg' },
    ],
    rows: [/* e.g. { id: 'O0', supplier: 'Kestrel', days: 3.1 } */],
  };

  ngAfterViewInit() {
    const grid = this.gridRef.grid;
    const tile = this.tilesEl.nativeElement.appendChild(document.createElement('div'));

    // interval() is the range the mean is pinned to, computed over the filtered
    // rows. The tile shows it under the value.
    createStat({ grid, container: tile, title: 'Mean lead time', of: 'days', fn: 'avg',
      interval: (value: any, g: any) => g.statistics.interval('days'), footer: '95% confidence interval' });

    // error: true draws each mean's interval as a whisker, computed from the
    // readings behind the bar. The chart reads the same grid as the tile.
    createChart({ grid, container: this.chartEl.nativeElement, type: 'bar', x: 'supplier', y: { col: 'days', fn: 'avg' },
      error: true, title: 'Mean lead time by supplier, with confidence interval' });
  }
}

bootstrapApplication(AppComponent);