Skip to main content
100%

Toggling element visibility in v4

✓ Published0🌍 Public
Dd3noob
Last edited Aug 16, 2016
Created on Aug 16, 2016

A dual-line chart displays close and open prices from a CSV file over time, with each line assigned a distinct color (steel blue and red) and its own y-axis scale. Users can toggle the visibility of either line by clicking on its corresponding legend text. The code uses d3.csv to load data, d3.timeParse to parse dates, and d3.line, d3.scaleTime, and d3.scaleLinear to construct the paths and axes. Clicking a legend label toggles the line’s opacity via d3.select and style updates, with an active flag tracking visibility state.

AI-generated description

This is a multiple line graph demonstrating how to show / hide elements by clicking on other elements. This was written using d3.js v4 and is a follow on to the multiple line graph example here.

This graph is part of the code samples for the update to the book D3 Tips and Tricks to version 4 of d3.js.

Similar vizzes