It is a common and necessary practice in data visualization to build legends. D3.js does not provide any helper function for that, meaning you have to build it from scratch. This document provides a few templates for categorical and continuous legend. Hopefully you will find one that suits your needs.
  
 
enter() approach: adding one element per entry of the key.
  
 
size variable to change the whole size.