Published
Edited
Dec 6, 2019
Insert cell
md`# JavaScript Pie Radar Chart`
Insert cell
path1 = {
const svg = d3.create('svg');
const diameter = 400;
const radius = diameter / 2;
svg.attr('width', diameter + borderWidth);
svg.attr('height', diameter + borderWidth);
const center = radius + borderWidth;
const axeCount = 3;
const spaceSize = 3;
const pxSpaceSize = 0;
for (let i = 0; i < 17; i ++) {
const currentRadius = radius - (i * 10);
const spaceSize = center * 2 / currentRadius;
createAxes(svg, center, currentRadius, axeCount, spaceSize);
}
return svg.node();
}
Insert cell
function createAxes(svg, center, radius, axeCount, spaceSize){
const axe = 360 / axeCount;

for (let i = 0; i < axeCount; i++){
createCircularOutlinePath(svg, center, radius - borderWidth, axe * i + spaceSize, axe * (i + 1) - spaceSize);
}
}
Insert cell
function createCircularOutlinePath(svg, center, radius, startAngle, endAngle){
const path = svg.append('path');
path.attr('stroke', '#446688');
path.attr('stroke-width', borderWidth);
path.attr('fill', 'none');
path.attr('stroke-linecap', 'round');
path.attr('d', describeArc(center, radius, startAngle, endAngle));
return path;
}
Insert cell

function describeArc(center, radius, startAngle, endAngle){

var start = polarToCartesian(center, radius, endAngle);
var end = polarToCartesian(center, radius, startAngle);

var largeArcFlag = endAngle - startAngle <= 180 ? "0" : "1";

var d = [
"M", start.x, start.y,
"A", radius, radius, 0, largeArcFlag, 0, end.x, end.y
].join(" ");

return d;
}

Insert cell
function polarToCartesian(center, radius, angleInDegrees) {
var angleInRadians = (angleInDegrees-90) * Math.PI / 180.0;

return {
x: center + (radius * Math.cos(angleInRadians)),
y: center + (radius * Math.sin(angleInRadians))
};
}
Insert cell
diameter = 200;
Insert cell
radius = diameter / 2;
Insert cell
borderWidth = 4;
Insert cell
d3 = require('d3')
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