Labels

Learn how to give labels to the axis.

We'll cover the following

Introduction

In this lesson, we are going to see another fundamental building block of drawing the chart, labels. Labels provide information for the chart and help to understand the information provided by the axis correctly. D3.js doesn’t have any explicit label component, but text is used to add labels to the graph. Curious to see how it works? Let’s jump right into the example.

Example

In the following example, we have been given data first, and we will need to draw an axis from the data then we will add the labels to the respective axis. In our example, the x-axis represents the days and the y-axis represents stock value. Our task is to add the respective labels to the x-axis and y-axis.

Get hands-on with 1200+ tech skills courses.