Public
Edited
Jun 4, 2024
Insert cell
Insert cell
chart = {
const width = 640;
const height = 400;
const margin = {top: 20, right: 30, bottom: 30, left: 40};



const svg = d3.create("svg")
.attr("width", width)
.attr("height", height);
const data = mlb_revenue_by_category_2022Sheet11;
const pie = d3.pie().value(d=>d.Percentage);
const arcs = pie(data);

const radius = (width -(margin.right + margin.left))/3;
const arc = d3.arc()
.innerRadius(radius-100)
.outerRadius(radius);


svg.append('g')
.attr('transform', `translate(${width/2} ${height/2})`)
.selectAll('.pie-svgs')
.data(arcs)
.join('path')
.attr('class','pie-svgs')
.attr("d",d => arc(d))
.attr('fill', (d,i)=>d3.schemeCategory10[i])
.attr('stroke','black')


svg.append('g')
.attr('transform', `translate(${width/2} ${height/2})`)
.selectAll('.pie-svgs')
.data(arcs)
.join('text')
.attr('class','pie-svgs')
.attr("x",d => arc.centroid(d)[0] - 55)
.attr("y",d => arc.centroid(d)[1])
.attr('stroke','lightblack')
.attr('stroke-width','1.5')
.attr('font-size','16px')
.text(d=>d.data.Category)

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

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