Skip to main content

sparkline: each team's weekly margin as a line in its colour

AFC, 2024
TeamMargin, weeks 1-18
KCSparkline of 17 values: min -38, max 19, last -38; mean line at 33
LACSparkline of 17 values: min -23, max 33, last 14; mean line at 66
DENSparkline of 17 values: min -31, max 38, last 38; mean line at 77
LVSparkline of 17 values: min -19, max 15, last -14; mean line at -7-7
BUFSparkline of 17 values: min -25, max 37, last -7; mean line at 99
MIASparkline of 17 values: min -21, max 19, last -12; mean line at -1-1
NYJSparkline of 17 values: min -26, max 21, last 12; mean line at -4-4
NESparkline of 17 values: min -33, max 16, last 7; mean line at -8-8
import { AFC_WEEKS_2024, type AfcWeeks } from "@sportsdataverse/examples/data";
import { defineTable } from "@sportsdataverse/sdvtables";
import { renderHTMLAsync } from "@sportsdataverse/sdvtables/html";

// reactablefmtr react_sparkline: one line per row from an array column. team + league colour each line (checked for
// contrast on the table's background); the bye week is a gap, the worst and best weeks are marked, and the dashed
// statline sits at the team's mean margin. Hover a chart for its summary.
const spec = defineTable<AfcWeeks>()
.columns((c) => [
c.text("team"),
c.sparkline("margins", {
label: "Margin, weeks 1-18",
team: "team",
league: "nfl",
highlightPoints: { min: "#C84630", max: "#3D8B6E" },
pointSize: 2,
statline: "mean",
chartWidth: 180,
}),
])
.title("AFC, 2024")
.build();
await renderHTMLAsync(spec, AFC_WEEKS_2024);

Tags: kind · sparkline · react_sparkline · reactablefmtr · nfl. All sdvtables examples.