Show the OJS code
= require('d3')
d3
= Inputs.radio(["2023", "2024"], {value: "2023", label: "Year to show"})
viewof year_to_show
= await d3.json(
books // This is my live API so it runs in your browser.
// Use your local API URL on your computer.
"https://api.andrewheiss.com/books_simple?year=" + year_to_show
)
= (books.count[0] === 1 ? " book read" : " books read")
book_noun
.plot({
Plottitle: books.count[0] + book_noun + " in " + year_to_show,
y: {
label: "Books read",
grid: false,
percent: false
,
}x: {
label: "Month",
domain: books.monthly_count.map(d => d.read_month_fct),
,
}marks: [
.ruleY([0]),
Plot.axisX({label: null, ticks: null}),
Plot.axisY({label: null, ticks: null}),
Plot
.barY(books.monthly_count, {
Plotx: "read_month_fct",
y: "count",
fill: "#f3752f",
tip: {
format: {
x: true,
y: true
}
}
})
] })