Public
Edited
Feb 9, 2023
Paused
3 forks
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// write answer here
Insert cell
Insert cell
Insert cell
Insert cell
// write your answer here
Insert cell
Insert cell
Insert cell
Insert cell
bardata = [
{xPos: 10, yPos: 50, width: 30, height: 50, color: 'blue'},
{xPos: 45, yPos: 20, width: 30, height: 80, color: 'red'},
{xPos: 80, yPos: 70, width: 30, height: 30, color: 'yellow'}
]
Insert cell
// write your answer here
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
bars = [
{name: 'a', value: 5, color: 'blue'},
{name: 'b', value: 8, color: 'red'},
{name: 'c', value: 3, color: 'yellow'}
]
Insert cell
width = 300
Insert cell
height = 100
Insert cell
x = d3.scaleBand()
.domain([0, 0]) // EDIT THIS LINE - need an array with the list of names
.range([0, width])
.padding(0.2)
Insert cell
Insert cell
y = d3.scaleLinear()
.domain([0, 0]) // EDIT THIS LINE
.range([0, height])
Insert cell
Insert cell
{
const svg = d3.create('svg').attr("width", width).attr("height", height);

svg.selectAll('rect')
.data(bars)
.join('rect')
.attr('fill', d => d.color)
.attr('x', d => 0) // EDIT THIS LINE
.attr('y', d => 0) // EDIT THIS LINE (remember that 0 starts at the top)
.attr('width', 0) // EDIT THIS LINE
.attr('height', d => 0); // EDIT THIS LINE

return svg.node();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3@7")
Insert cell
import {solution} from "@nyuvis/d3-introduction"
Insert cell
import {chart as scaleDiagram} from "@uw-info474/animated-scale-diagram"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more