This post describes how to build a button that changes the input dataset of a barplot. You need to understand how to draw a basic barplot first. It is a good way to understand the enter() and exit functions of d3.
Important note: This example does not update the X and Y axis, it works only if the 2 datasets have the same groups and same Y range. See here for an upgraded version