This video is available to students only

Drawing our chart

To set up our chart environment, we learn why we need two containers: wrapper and bounds.

Drawing our chart#

When drawing a chart, there are two containers whose dimensions we need to define: the wrapper and the bounds.

Chart dimensions

The wrapper contains the entire chart: the data elements, the axes, the labels, etc. Every SVG element will be contained inside here.

The bounds contain all of our data elements: in this case, our line.

This distinction will help us separate the amount of space we need for extraneous elements (axes, labels), and let us focus on our main task: plotting our data. One reason this is so important to define up front is the inconsistent and unfamiliar way SVG elements are sized.

When adding a chart to a webpage, we start with the amount of space we have available for the chart. Then we decide how much space we need for the margins, which will accommodate the chart axes and labels. What's left is how much space we have for our data elements.

We will rarely have the option to decide how large our timeline is and then build up from there. Our charts will need to be accommodating of window sizes, surrounding text, and more.


This page is a preview of Fullstack D3 Masterclass

No discussions yet