{
const parseMonth = d => {
let date = new Date(d.transaction_date);
return date.getMonth() + 1;
};
const withMonth = coffeeLowerManhattan1.map(d => ({
...d,
month: parseMonth(d)
}));
const monthCounts = Array.from(
d3.rollup(
withMonth,
v => v.length,
d => d.month
),
([month, count]) => ({ month, count })
);
const topMonth = monthCounts.sort((a, b) => d3.descending(a.count, b.count))[0];
return vl.markBar()
.data(monthCounts)
.encode(
vl.x().fieldO("month").title("Month"),
vl.y().fieldQ("count").title("Number of Transactions"),
vl.color().fieldN("month").legend(null)
)
.title("Transactions per Month")
.width(400)
.height(300)
.render()
}