最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Trying to remove border of arc on canvas - Stack Overflow

programmeradmin4浏览0评论

I drew a circle using the HTML canvas arc method, but I want to remove the border of the circle. I tried to set lineWidth = 0 but it doesn't seem to work. Is there a way to remove the border of a circle in canvas?

$(document).ready(function() {
    pie_chart = $('#pie_chart');
    var p = pie_chart[0].getContext('2d');

    var canvas_width = pie_chart.width();
    var canvas_height = pie_chart.height();

    p.beginPath();
    p.arc(canvas_width/2, canvas_height/2, 150, 0 , Math.PI * 2);
    p.lineWidth = 0;
    p.stroke();
    p.fillStyle = '#777';
    p.fill();
});

I drew a circle using the HTML canvas arc method, but I want to remove the border of the circle. I tried to set lineWidth = 0 but it doesn't seem to work. Is there a way to remove the border of a circle in canvas?

$(document).ready(function() {
    pie_chart = $('#pie_chart');
    var p = pie_chart[0].getContext('2d');

    var canvas_width = pie_chart.width();
    var canvas_height = pie_chart.height();

    p.beginPath();
    p.arc(canvas_width/2, canvas_height/2, 150, 0 , Math.PI * 2);
    p.lineWidth = 0;
    p.stroke();
    p.fillStyle = '#777';
    p.fill();
});
Share Improve this question edited Apr 22, 2016 at 1:41 user1693593 asked Apr 23, 2015 at 2:25 blank_kumablank_kuma 3396 silver badges17 bronze badges 2
  • 2 Set stroke colour to be equal to fill colour? – Amadan Commented Apr 23, 2015 at 2:27
  • @Amadan either that or transparent – Andrew Koroluk Commented Apr 23, 2015 at 2:30
Add a ment  | 

1 Answer 1

Reset to default 14

The simple answer is: just drop the stroke() call:

p.beginPath();
p.arc(canvas_width/2, canvas_height/2, 150, 0 , Math.PI * 2);
p.lineWidth = 0;
//p.stroke();
p.fillStyle = '#777';
p.fill();
发布评论

评论列表(0)

  1. 暂无评论