Skip to main content

dataBar: diverging bars for a column with negatives

AFC, 2024
TeamNet EPA/play
KC
0.063
LAC
0.101
DEN
0.108
LV
-0.146
BUF
0.190
MIA
-0.019
NYJ
-0.045
NE
import { STANDINGS, type Standing } from "@sportsdataverse/examples/data";
import { defineTable } from "@sportsdataverse/sdvtables";
import { renderHTMLAsync } from "@sportsdataverse/sdvtables/html";

// A column with a negative value draws its bars either side of a centre line; with two fill colours the first paints
// the negatives. New England's missing net EPA stays blank.
const spec = defineTable<Standing>()
.columns((c) => [
c.text("team"),
c.dataBar("net_epa", {
label: "Net EPA/play",
fill: ["#C84630", "#5DA271"],
textPosition: "outside-end",
numberFormat: { digits: 3 },
width: "260px",
}),
])
.title("AFC, 2024")
.build();
await renderHTMLAsync(spec, STANDINGS);

Tags: formatter · dataBar · data_bars · reactablefmtr · posNeg. All sdvtables examples.