Published
Edited
Aug 5, 2019
2 stars
Insert cell
Insert cell
chart = {
const svg = d3.select(DOM.svg(width, height))
const g = svg.attr('width', width + margin.left)
.attr('height', height + margin.top + margin.bottom)
.append('g')
.attr('transform', 'translate(' + margin.left + ',0)')
g.append('g')
.attr('transform', 'translate(0,' + height + ')')
.call(d3.axisBottom(x_scale))
g.append('g')
.call(d3.axisLeft(y_scale))
dataset.map((item) => {
svg.selectAll('.dot')
.data(item.data)
.enter().append('circle')
.attr('r', 5)
.attr('fill', item.color)
.attr('cx', (d, i) => (x_scale(i) + margin.left))
.attr('cy', (d) => y_scale(d.y))
})
return svg.node()
}
Insert cell
dataset = [{ data:gd(), color: '#CA2C68' }, { data: gd(), color: '#0067B0'}, { data: gd(), color: '#3C4A59'}]
Insert cell
gd = () => d3.range(7).map((d) => ({ y: d3.randomUniform()()}))
Insert cell
line = d3.line()
.x((d, i) => (x_scale(i) + margin.left))
.y((d) => y_scale(d.y))
Insert cell
y_scale = d3.scaleLinear()
.domain([0, 1])
.range([height, 0])
Insert cell
x_scale = d3.scaleLinear()
.domain([0, 6])
.range([0, width - margin.left - margin.right])
Insert cell
height = 350
Insert cell
margin = ({ top: 50, right: 50, bottom: 50, left: 50})
Insert cell
d3 = require("d3@5")
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