1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| <canvas id="ideo"> 你的浏览器不支持canvas,请升级浏览器 </canvas>
<script> var canvas = document.getElementById("ideo"); var tex = canvas.getContext("2d"); //设置画布的宽高以及边框样式 canvas.width = 1000; canvas.height = 500; canvas.style.border = "1px solid blue"; tex.moveTo(100,400); //起始点即原点 tex.lineTo(800,400); //x轴 tex.lineTo(790,410); //x轴下半部分的箭头 tex.moveTo(800,400); //设置画笔到该点 tex.lineTo(790,390); //x轴上半部分箭头 tex.strokeStyle = "red"; //设置x轴的颜色为红色 tex.stroke();//描边 tex.beginPath();//开启一个新状态 tex.moveTo(100,400); //起始点即原点 tex.lineTo(100,50); //y轴 tex.lineTo(110,60); //y轴右半部分箭头 tex.moveTo(100,50); //设置画笔到该点 tex.lineTo(90,60); //设置y轴左半部分箭头 tex.strokeStyle = "red"; //设置y轴的颜色为红色 tex.stroke(); //描边 tex.beginPath(); //开启一个新状态 tex.moveTo(100,400); //画笔回到起始原点 //以下为点的坐标,可以任意设置 tex.lineTo(150,250); tex.lineTo(250,150); tex.lineTo(600,150); tex.lineTo(750,80); //描边样式 tex.strokeStyle = "green"; tex.stroke(); </script>
|