glops
New Member
Posts: 8
|
Post by glops on Jun 23, 2015 10:24:03 GMT
Hi I try to make a survey from an XML (all the questions)...and that is ok then at the end I would like to display a little pie chart..like a simple www.scriptol.com/html5/canvas/circle.phpfunction pie(ctx, w, h, datalist) { var radius = h / 2 - 5; var centerx = w / 2; var centery = h / 2; var total = 0; for(x=0; x < datalist.length; x++) { total += datalist[x]; }; var lastend=0; var offset = Math.PI / 2; for(x=0; x < datalist.length; x++) { var thispart = datalist[x]; ctx.beginPath(); ctx.fillStyle = colist[x]; ctx.moveTo(centerx,centery); var arcsector = Math.PI * (2 * thispart / total); ctx.arc(centerx, centery, radius, lastend - offset, lastend + arcsector - offset, false); ctx.lineTo(centerx, centery); ctx.fill(); ctx.closePath(); lastend += arcsector; } }
var datalist= new Array(35, 25, 20, 12, 7, 1); var colist = new Array('blue', 'red', 'green', 'orange', 'gray', 'yellow'); var canvas = document.getElementById("canvas3"); var ctx = canvas.getContext('2d'); pie(ctx, canvas.width, canvas.height, datalist); 1st... do I need to declare canvas3 in the html body part in the movie ? Where do I need to save the js ? I have tried tons of things and I'm unable to display a chart... document.getElementById is not recognized Do you have an example of such feature or how to easily call jQuery or JavaScript real functions ? thanks
|
|
|
Post by Hippani on Jun 23, 2015 21:28:53 GMT
jquery is pretty much incompatible. The best way to use this sort of thing is with the web page object which allows you to embed a separate page.
Charts are another thing on our list. I'll +1 the suggestion.
You could always try using the 'segment' shape to create a pie chart, but it would be difficult to make that dynamic.
|
|