pct: a share shown as a percentage
| Team | Wins | Losses | Win % |
|---|---|---|---|
| KC | 15 | 2 | 88.2% |
| LAC | 11 | 6 | 64.7% |
| DEN | 10 | 7 | 58.8% |
| LV | 4 | 13 | 23.5% |
| BUF | 13 | 4 | 76.5% |
| MIA | 8 | 9 | 47.1% |
| NYJ | 5 | 12 | 29.4% |
| NE | 4 | 13 | 23.5% |
import { STANDINGS } from "@sportsdataverse/examples/data";
import { defineTable } from "@sportsdataverse/sdvtables";
import { renderHTMLAsync } from "@sportsdataverse/sdvtables/html";
// pct multiplies by 100 (scale: true, the default): pass shares, not percentages.
const rows = STANDINGS.map((r) => ({ ...r, win_share: r.wins / (r.wins + r.losses + r.ties) }));
const spec = defineTable<(typeof rows)[number]>()
.columns((c) => [c.text("team"), c.int("wins"), c.int("losses"), c.pct("win_share", { label: "Win %" })])
.title("AFC, 2024")
.build();
await renderHTMLAsync(spec, rows);
Tags: kind · pct. All sdvtables examples.