Skip to content

Instantly share code, notes, and snippets.

@LiorB-D
Last active May 20, 2021 05:14
Show Gist options
  • Save LiorB-D/ba302c76a84d2973ffbe1fd115ce026d to your computer and use it in GitHub Desktop.
Save LiorB-D/ba302c76a84d2973ffbe1fd115ce026d to your computer and use it in GitHub Desktop.
import './App.css';
import * as d3 from 'd3'
import {useEffect, useState} from 'react'
function App() {
useEffect(() => {
// Create a dataset of pets and the amount of people that own them
let dataSet = [
{subject: "Dogs", count: 150},
{subject: "Fish", count: 75},
{subject: "Cats", count: 135},
{subject: "Bunnies", count: 240},
]
// Generate a p tag for each element in the dataSet with the text: Subject: Count
d3.select('#pgraphs').selectAll('p').data(dataSet).enter().append('p').text(dt => dt.subject + ": " + dt.count)
}, [])
return (
<div className = "App">
<div id="pgraphs"></div> // Create a div to house our p tags
</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment