Skip to main content
100%

Untitled

✓ Published0🌍 Public
JJamesHop31
Last edited Jun 2, 2022
Created on Jun 2, 2022
Forked from dataset#2

This example displays a black terminal-style interface that reports the dimensions of a dataset loaded from a CSV file, showing the row count, column count, and file size in kilobytes. It also prints the first ten rows of the data, which contains country populations, as formatted JSON. The visualization uses the d3.csv function to parse the data and d3.select to append multiple pre elements to the page body. The code imports d3.csvFormat to calculate the data size and uses d3.v7.

AI-generated description

import { select, csv, csvFormat } from 'd3';

const kilobytes = data => Math.ceil(csvFormat(data).length / 1024);

const body = select('body');

csv('data.csv').then(data => { body .append('pre') .text([ ${data.length} rows, ${Object.keys(data[0]).length} columns, ${kilobytes(data)} KB ].join(', '));

body .append('pre') .text('First 10 rows:');

body .append('pre') .text(JSON.stringify(data.slice(0, 10), null, 2)); });

MIT Licensed

Similar vizzes