Skip to main content
100%

Loading and Parsing CSV Data

✓ Published0🌍 Public
TTHANNULA
Last edited Mar 4, 2021
Created on Mar 4, 2021
Forked from HTML Starter

This example demonstrates the size and structure of a CSV file by displaying its kilobytes, row count, and column count. The visualization loads a remote dataset containing CSS named colors, then parses it with the `d3.csvParse` function from the D3 v6 library. The code uses the `fetch` API with async/await to retrieve the text, then computes the data dimensions and displays them in a large `<pre>` element. The alternative approach in `index.html` uses `d3.csv()` and `d3.csvFormat()` to achieve the same result.

AI-generated description

A program that loads and parses some CSV data. PARSING CSV Data using D3!!

with fetch async and await

const fetchText = async (url) => { const response = await fetch(url); return await response.text(); }; fetchText(csvUrl).then(text => { const data = d3.csvParse(text); let message = ''; message += Math.round(text.length / 1024) + ' kB\n'; message += data.length + ' rows\n'; message += data.columns.length + ' columns'; document.getElementById('message-container').textContent = message; });

MIT Licensed

Similar vizzes