Search⌘ K

How to Add a Title to Your Graph

Learn to enhance your D3 visualizations by adding a centered title above your graph. This lesson guides you through modifying margins and using text elements with specific styling directly in JavaScript to create clean, readable graph titles.

We'll cover the following...

If you’ve completed the lessons about adding the axis labels, then most of this will come as no surprise.

What we want to do to add a title to the graph is add a text element (just a few words) that will appear above the graph and centered left to right.

We’ll start with our default code for our simple graph.

Preparation

Because we’re going to be adding a ...