Drawing grid lines

Quite often, we will need horizontal and vertical grid lines to be drawn in consistency with the ticks on both x and y axes. As we have shown in the previous recipe, typically, we don't have, or don't want to have, precise control of how ticks are rendered on D3 axes. Therefore, we might not know how many ticks are present and their values, before they are rendered. This is especially true if you are building a reusable visualization library, where it is impossible to know the tick configuration ahead of its time. In this recipe, we will explore some useful techniques for drawing consistent grid lines on Axis without actually needing to know the tick values.

Getting ready

Open your local copy of the following file in your web ...

Get Data Visualization with D3 4.x Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.