How to get the bin values from a Plot?

To get 14, you need to ignore the empty bins:

d3.median(
  d3
    .bin()
    .value((d) => d.date)
    .thresholds(thresholdTime(100))(data),
  (d) => d.length || NaN 
)

If you call:

init = Plot.rectY(
  data,
  Plot.binX({ y: "count" }, { x: "date", thresholds: 100 })
).initialize()

you can then inspect the bins in init.data, and their bounds in init.channels.x1.value and init.channels.x2.value

2 Likes