Published
Edited
Oct 22, 2018
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
Insert cell
Insert cell
Insert cell
setup = function(x0,x1,y0,y1,xlabel, ylabel){
var svg = d3.select(DOM.svg(height, height))
var x = d3.scaleLinear()
.domain([x0,x1])
.range([margin.left, height - margin.right])
var y = d3.scaleLinear()
.domain([y0,y1])
.range([height - margin.bottom, margin.top])
var yAxis = g => g
.attr("transform", `translate(${x(0)},0)`)
.call(d3.axisLeft(y))
var xAxis = g => g
.attr("transform", `translate(0,${y(0)})`)
.call(d3.axisBottom(x))
svg.append("g").call(xAxis)
svg.append('g').call(yAxis)
svg.append('text').text(xlabel).attr('font-weight','bold')
.attr("transform", `translate(${x.range()[1]+margin.right/5},${y(0)})`)
svg.append('text').text(ylabel).attr('font-weight','bold')
.attr("transform", `translate(${x(0)},${y.range()[1]-margin.top/10})`)
return {svg:svg, x:x, y:y}
}
Insert cell
Insert cell
Insert cell
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