Skip to main content
100%

Multiple line graphs with labels

✓ Published0🌍 Public
Dd3noob
Last edited Nov 30, 2019
Created on Jan 24, 2014

Two line graphs show the daily open and close prices of a stock over time, with each line labeled at its right endpoint. The blue line represents closing prices and the red line represents opening prices, plotted against a time-based x-axis and linear y-axis. The visualization uses D3.js version 3.5.17 with `d3.svg.line` to generate the paths, `d3.time.scale` for the x-axis, and `d3.scale.linear` for the y-axis, reading data from a CSV file. Labels are positioned using the final data point’s y-coordinate, as the CSV data is ordered newest-first.

AI-generated description

This is an example of a line graph with multiple lines and labels at the end of those lines.

Created in responce to a question on d3noob.org

A few points to note:

  1. The csv file starts with the newest data point and ends with the oldest. If you needed to get the 'y' position of the last point in the array you will need to use data[data.length-1].open rather than data[0].open.

  2. I've left some console.log calls in the code as small demos.

  3. The script makes the adjustment for scale using the y function.

mit Licensed

Similar vizzes