Data Visualization project

In this example below you will see how to do a Data Visualization project with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by Cylthus, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright Cylthus ©
  • HTML
  • CSS
  • JavaScript
    

/*Downloaded from https://www.codeseek.co/Cylthus/data-visualization-project-RgERLm */
    
body{
	background-color:#FF6565;
	display:flex;
	align-items:center;
	justify-content:center;
}
svg{
	background-color:#d3d3d3;
	border-radius:15px;
	margin-top:35px;
}
.graphText{
	color:white;
}
.title{
	color:red;
}



/*Downloaded from https://www.codeseek.co/Cylthus/data-visualization-project-RgERLm */
    const width = 400;
const height = 400;

const canvas = d3.select("body").append("svg").attr("width",width).attr("height",height);

var data = [900,10,340,500,98];
var colors = d3.scaleLinear()
						.domain([0,4])
						.range(["grey","lightblue"]);

var group = canvas.append("g")						.attr("transform","translate(200,200)");

var pie = d3.pie().value((d)=>{return d;});

var arc = d3.arc()
					.innerRadius(70)
					.outerRadius(100);

var arcs = group.selectAll(".arc")
						.data(pie(data))
						.enter()
						.append("g")
						.attr("class","arc");

arcs.append("path").attr("d",arc).attr("fill",(d,i)=>{return colors(i)}).append("svg:title").text((d)=>{return d.value});

arcs.append("text").text((d)=>{return d.data}).attr("transform",(d)=>{return "translate("+arc.centroid(d)+")"}).attr("text-anchor","middle").attr("fill","white");

Comments