This post describes how to build a button that changes the color of a
barplot. You need to understand how to
draw a basic barplot first. It is a
good way to understand how to build a button in html, and
how to build a simple function in Javascript. This
example works with d3.js v4 and v6
button in the html part. Note the
onclick attribute: it means that the
changeColor() function will be triggered when
you click on it
changeColor() function in the
Javascript part. It basically select all the rectangles of
the plot and change their fill attribute.