Jump to content
  • 0

Проблема С Canvas


Mal4ishnik
 Share

Question

Не работает код, сто раз уже проверил, вроде все правильно, используется тег canvas, может кто знает что неправильно?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Тест</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<script type="text/javascript">
function makeCanvas(id, height, width){
var canvas = document.createElement("canvas");
canvas.id = id;
canvas.height = height;
canvas.width = width;
return canvas;
}

function makePieChart(canvas, colors, data, cx, cy, r) {
canvas = document.getElementById(canvas);
var p = canvas.getContext("2d");
p.lineWidth = 1;
p.strokeStyle = "#693";

var total = 0;
for(var i = 0; i < data.length; i++) total += data[i];

var angles = [];
for(var i = 0; i < data.length; i++) angles[i] = data[i]/total*2*Math.PI;
startangle = -Math.PI/2;
document.write(startangle + "<br/>");

for(var i = 0; i < data.length; i++){
var endangle = startangle + angles[i];
p.beginPath();
p.moveTo(cx,cy);
p.arc(cx,cy,r,startangle,endangle,false);
p.closePath();
p.fillStyle = colors[i];
p.fill();
p.stroke();


startangle = endangle;

}
}


function init(){
var canvas = makeCanvas("myCanvas", 600, 800);
document.body.appendChild(canvas);
makePieChart("myCanvas",["#99cc66", "#006699", "#ffff00", "#ff6633", "#cc0033", "#cc00cc"], [12, 32, 56, 64, 5, 90], 300, 300, 200);

}
</script>
<body onload="init()"></body>
</html>

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy