简体   繁体   中英

What is the best way to implement the complex circular charts (d3.js?)

I am trying to implement a chart something like this 在此处输入图片说明

I wanted to know id d3.js library would allow me to plot such kind of graphs.

Any help would be appreciated.

There is no need for a library, Canvas can draw the graph, animate it, scale it, or anything you might need fairly easily. The Arc method is particularly relevant.

ctx.beginPath();
//Start the arc at 90 degrees, aka the bottom.
//End the arc at 360 - (360 degrees * 46% expressed as 0.46) + our starting 90 degrees.
//Pi/180 converts degrees to radians.
ctx.arc(64,64,32,284.4*(Math.PI/180),90*(Math.PI/180));
ctx.lineWidth=8;
ctx.strokeStyle="green"
ctx.stroke();

If somebody's still looking for this, here's the entire thing. Just use HTML 5 canvas tag and use it's 2D context to draw. Drawing part is in JS.

 var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); ctx.beginPath(); ctx.arc(100, 75, 50, 1.5 * Math.PI, .5 * Math.PI, false); ctx.lineWidth=8; ctx.strokeStyle="green"; ctx.stroke(); ctx.beginPath(); ctx.arc(100, 75, 42, 1.5 * Math.PI, .7 * Math.PI, false); ctx.lineWidth=8; ctx.strokeStyle="blue"; ctx.stroke(); ctx.beginPath(); ctx.arc(100, 75, 34, 1.5 * Math.PI, .6 * Math.PI, false); ctx.lineWidth=8; ctx.strokeStyle="red"; ctx.stroke(); 
 <!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;"> Your browser does not support the HTML5 canvas tag.</canvas> </body> </html> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM