Show the OJS code
d3 = require('d3')
viewof year_to_show = Inputs.radio(["2023", "2024"], {value: "2023", label: "Year to show"})
books = await d3.json(
// 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
)
book_noun = (books.count[0] === 1 ? " book read" : " books read")
Plot.plot({
title: 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: [
Plot.ruleY([0]),
Plot.axisX({label: null, ticks: null}),
Plot.axisY({label: null, ticks: null}),
Plot.barY(books.monthly_count, {
x: "read_month_fct",
y: "count",
fill: "#f3752f",
tip: {
format: {
x: true,
y: true
}
}
})
]
})