Public
Edited
Oct 5, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d3.scaleLinear()
.domain([0, 1])
.range([0, 100])(5)
Insert cell
d3.scaleLinear()
.domain([0, 1])
.range([0, 100])(.5)
Insert cell
myLinearScale = d3.scaleLinear()
.domain([0, 1])
.range([0, 100])
Insert cell
myLinearScaleShort = d3.scaleLinear([0, 1], [0, 100])
Insert cell
myLinearScaleShort(5)
Insert cell
myLinearScale(5)
Insert cell
sepalLength = iris.map((d) => d.sepalLength)
Insert cell
minVal = d3.min(sepalLength)
Insert cell
d3.scaleLinear().domain([minVal, maxVal]).range([0, 1])(0.5)
Insert cell
extentValue = d3.extent(sepalLength)
Insert cell
d3
.scaleLinear()
.domain(extentValue)
.range([0, 1])(0.5)

Insert cell
d3.extent(iris, (d) => d.sepalLength)
Insert cell
maxVal = d3.max(sepalLength)
Insert cell
extract = (value, data) => {
return data.map((d)=> d[value]);
}
Insert cell
Insert cell
Insert cell
myOrdinalScale= d3
.scaleOrdinal()
.domain(["apple", "orange", "bannana"])
.range(["red", "orange", "yellow"])
Insert cell
myOrdinalScale("bannana")
Insert cell
htl.html`<div style='background-color: ${myOrdinalScale(
"bannana"
)}'>${"bannana"}</div>`
Insert cell
myDataOrdinalScale= d3
.scaleOrdinal()
.domain(Array.from(new Set(iris.map((d) => d.species))))
.range(["red", "orange", "yellow"])
Insert cell
myDataOrdinalScale("setosa")
Insert cell
iris
Insert cell
Array.from(new Set(iris.map((d) => d.species)))
Insert cell
Insert cell
Insert cell
Insert cell
width = 600
Insert cell
height = 400
Insert cell
{
const width = 600
const height = 400
const margin = {top: 20, bottom: 20, left: 20, right: 20};
const svg = d3
.create("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.style("border", "1px dotted #000");
const g = svg
.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`);

g.append("rect").attr("width", width).attr("height", height);
return svg.node()
}
Insert cell
Insert cell
Insert cell
{
const width = 600
const height = 400
const margin = {top: 20, bottom: 20, left: 50, right: 20};
const svg = d3
.create("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.style("border", "1px dotted #000");
const g = svg
.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`);

//g.append("rect")
// .attr("width", width)
// .attr("height", height)
// .style("fill", "#ccc");

const x = d3
.scaleLinear()
.domain(d3.extent(iris, (d) => d["sepalLength"]))
.range([0, width]);

const y = d3
.scaleLinear()
.domain(d3.extent(iris, (d) => d["sepalWidth"]))
.range([height, 0]);


const colorScale = d3
.scaleOrdinal()
.domain(Array.from(new Set(iris.map((d) => d.species))))
.range(["red", "orange", "yellow"]);


g.append("g")
.selectAll("circle")
.data(iris)
.join("circle")
.attr("r", 3)
.attr("cx", (d) => x(d.sepalLength))
.attr("cy", (d) => y(d.sepalWidth))
.style("fill", (d) => colorScale(d.species));

return svg.node();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
iris.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more