Skip to main content

pct: a share shown as a percentage

AFC, 2024
TeamWinsLossesWin %
KC15288.2%
LAC11664.7%
DEN10758.8%
LV41323.5%
BUF13476.5%
MIA8947.1%
NYJ51229.4%
NE41323.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.