javascript - add border to the outer area of slice in pie -



javascript - add border to the outer area of slice in pie -

http://jsfiddle.net/wm7pwl2w/8/

how can add together border outer area of piece in pie? please check jsfiddle. have implemented polar area chart here. need each border of different color can specify. illustration refer image

var canvas = document.getelementbyid("canvas"); var ctx = canvas.getcontext('2d'); console.log(ctx); var center = { x: 200, y: 150 }; var mycolor = ["#ccc", "#ccc", "#ccc", "#ccc", "#c01c3f"]; var mydata = [20, 40, 50, 70, 100]; var myradius = [150, 120, 80, 100, 70]; var mydistance = [5, 5, 2, 2, 2]; var mytext = ['first', 'second', 'third', 'fourth', 'fifth']; function gettotal(data) { var mytotal = 0; (var j = 0; j < data.length; j++) { mytotal += (typeof data[j] == 'number') ? data[j] : 0; } homecoming mytotal; } function plotdata() { var lastend = 0; var mytotal = gettotal(mydata); ctx.clearrect(0, 0, canvas.width, canvas.height); ctx.textalign = 'center'; ctx.textbaseline = 'middle'; //ctx.strokestyle = 'rgba(255,255,255,0.5)'; ctx.linewidth = 1; ctx.font="15px arial"; (var = 0; < mydata.length; i++) { ctx.save(); ctx.fillstyle = mycolor[i]; ctx.beginpath(); ctx.translate(center.x, center.y); var thisangle = (math.pi * 2 * (mydata[i] / mytotal)); ctx.rotate(lastend + thisangle / 2); ctx.translate(mydistance[i], 0); ctx.moveto(0, 0); ctx.arc(0, 0, myradius[i], -(thisangle / 2), thisangle / 2, false); ctx.closepath(); ctx.fill(); // ctx.stroke(); ctx.fillstyle = '#fff'; ctx.translate(0.6 * myradius[i], 0); ctx.rotate(-(lastend + thisangle / 2)); ctx.filltext(mytext[i], 0, 0); ctx.restore(); lastend += thisangle; } } plotdata();

thanks help.

you need in 2 steps, first fill shape stroke arc. need utilize beginpath() outer border after filling not stroke finish shape.

... ctx.closepath(); ctx.fill(); // original code stops // insert code ctx.beginpath(); ctx.strokestyle = '#079'; ctx.linewidth = 9; ctx.arc(0, 0, myradius[i], -(thisangle / 2), thisangle / 2); ctx.stroke(); // original code continues... // ctx.stroke(); ctx.fillstyle = '#fff'; ...

updated fiddle

javascript html5 html5-canvas

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -