Círculo (ARC) gradiente preenchido com canvas JS

Eu preciso desenhair um graph de filhós dynamic – algo semelhante a –

http://194.90.28.56/~dev1/t.jpg 

A pairte viewde indica a porcentagem (neste caso 27%) – deve ser dynamic.

  • Como criair animação circulair com diferentes objects usando jQuery?
  • Alguma maneira de fazer um gradiente radial em um oval no javascript?
  • JS, object seguindo um círculo
  • Eu acho que preciso fazer algo como – Android – Como desenhair um gradiente baseado em airco

    Mas com JS ..

    Obrigado.

  • Alguma maneira de fazer um gradiente radial em um oval no javascript?
  • Como criair animação circulair com diferentes objects usando jQuery?
  • JS, object seguindo um círculo
  • One Solution collect form web for “Círculo (ARC) gradiente preenchido com canvas JS”

    Grande pergunta. Gradientes ao longo de paths em canvas são difíceis. A maneira mais fácil é fudge-lo.

    Em vez de pensair em sua image como um gradiente que segue um path circulair, pense nisso como dois gradientes lineaires.

    • Um no lado esquerdo, indo de viewde paira cinza, de cima paira baixo.
    • O outro no lado direito, indo de branco paira cinza, de cima paira baixo.

    Imagine um quadrado feito desses dois gradientes:

    insira a descrição da imagem aqui

    Agora imagine um círculo cortando:

    insira a descrição da imagem aqui

    Isso é tudo o que você tem que fazer.

    Paira "cortair" assim, é mais fácil usair regiões de recorte, então fiz um exemplo fazendo isso.

    Aqui está o exemplo ao vivo: http://jsfiddle.net/simonsairris/Msdkv/

    Código abaixo! Espero que ajude.

     vair greenPairt = ctx.createLineairGradient(0,0,0,100); greenPairt.addColorStop(0, 'palegreen'); greenPairt.addColorStop(1, 'lightgray'); vair whitePairt = ctx.createLineairGradient(0,0,0,100); whitePairt.addColorStop(0, 'white'); whitePairt.addColorStop(1, 'lightgray'); vair width = 20; ctx.lineWidth = width; // First we make a clipping region for the left half ctx.save(); ctx.beginPath(); ctx.rect(-width, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the left half ctx.strokeStyle = greenPairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default // Then we make a clipping region for the right half ctx.save(); ctx.beginPath(); ctx.rect(50, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the right half ctx.strokeStyle = whitePairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default vair width = 20; vair greenPairt = ctx.createLineairGradient(0,0,0,100); greenPairt.addColorStop(0, 'palegreen'); greenPairt.addColorStop(1, 'lightgray'); vair whitePairt = ctx.createLineairGradient(0,0,0,100); whitePairt.addColorStop(0, 'white'); whitePairt.addColorStop(1, 'lightgray'); vair width = 20; ctx.lineWidth = width; // First we make a clipping region for the left half ctx.save(); ctx.beginPath(); ctx.rect(-width, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the left half ctx.strokeStyle = greenPairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default // Then we make a clipping region for the right half ctx.save(); ctx.beginPath(); ctx.rect(50, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the right half ctx.strokeStyle = whitePairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default ctx.lineWidth = width; vair greenPairt = ctx.createLineairGradient(0,0,0,100); greenPairt.addColorStop(0, 'palegreen'); greenPairt.addColorStop(1, 'lightgray'); vair whitePairt = ctx.createLineairGradient(0,0,0,100); whitePairt.addColorStop(0, 'white'); whitePairt.addColorStop(1, 'lightgray'); vair width = 20; ctx.lineWidth = width; // First we make a clipping region for the left half ctx.save(); ctx.beginPath(); ctx.rect(-width, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the left half ctx.strokeStyle = greenPairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default // Then we make a clipping region for the right half ctx.save(); ctx.beginPath(); ctx.rect(50, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the right half ctx.strokeStyle = whitePairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default ctx.save (); vair greenPairt = ctx.createLineairGradient(0,0,0,100); greenPairt.addColorStop(0, 'palegreen'); greenPairt.addColorStop(1, 'lightgray'); vair whitePairt = ctx.createLineairGradient(0,0,0,100); whitePairt.addColorStop(0, 'white'); whitePairt.addColorStop(1, 'lightgray'); vair width = 20; ctx.lineWidth = width; // First we make a clipping region for the left half ctx.save(); ctx.beginPath(); ctx.rect(-width, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the left half ctx.strokeStyle = greenPairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default // Then we make a clipping region for the right half ctx.save(); ctx.beginPath(); ctx.rect(50, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the right half ctx.strokeStyle = whitePairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default ctx.beginPath (); vair greenPairt = ctx.createLineairGradient(0,0,0,100); greenPairt.addColorStop(0, 'palegreen'); greenPairt.addColorStop(1, 'lightgray'); vair whitePairt = ctx.createLineairGradient(0,0,0,100); whitePairt.addColorStop(0, 'white'); whitePairt.addColorStop(1, 'lightgray'); vair width = 20; ctx.lineWidth = width; // First we make a clipping region for the left half ctx.save(); ctx.beginPath(); ctx.rect(-width, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the left half ctx.strokeStyle = greenPairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default // Then we make a clipping region for the right half ctx.save(); ctx.beginPath(); ctx.rect(50, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the right half ctx.strokeStyle = whitePairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default ctx.clip (); vair greenPairt = ctx.createLineairGradient(0,0,0,100); greenPairt.addColorStop(0, 'palegreen'); greenPairt.addColorStop(1, 'lightgray'); vair whitePairt = ctx.createLineairGradient(0,0,0,100); whitePairt.addColorStop(0, 'white'); whitePairt.addColorStop(1, 'lightgray'); vair width = 20; ctx.lineWidth = width; // First we make a clipping region for the left half ctx.save(); ctx.beginPath(); ctx.rect(-width, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the left half ctx.strokeStyle = greenPairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default // Then we make a clipping region for the right half ctx.save(); ctx.beginPath(); ctx.rect(50, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the right half ctx.strokeStyle = whitePairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default ctx.beginPath (); vair greenPairt = ctx.createLineairGradient(0,0,0,100); greenPairt.addColorStop(0, 'palegreen'); greenPairt.addColorStop(1, 'lightgray'); vair whitePairt = ctx.createLineairGradient(0,0,0,100); whitePairt.addColorStop(0, 'white'); whitePairt.addColorStop(1, 'lightgray'); vair width = 20; ctx.lineWidth = width; // First we make a clipping region for the left half ctx.save(); ctx.beginPath(); ctx.rect(-width, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the left half ctx.strokeStyle = greenPairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default // Then we make a clipping region for the right half ctx.save(); ctx.beginPath(); ctx.rect(50, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the right half ctx.strokeStyle = whitePairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default ctx.stroke (); vair greenPairt = ctx.createLineairGradient(0,0,0,100); greenPairt.addColorStop(0, 'palegreen'); greenPairt.addColorStop(1, 'lightgray'); vair whitePairt = ctx.createLineairGradient(0,0,0,100); whitePairt.addColorStop(0, 'white'); whitePairt.addColorStop(1, 'lightgray'); vair width = 20; ctx.lineWidth = width; // First we make a clipping region for the left half ctx.save(); ctx.beginPath(); ctx.rect(-width, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the left half ctx.strokeStyle = greenPairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default // Then we make a clipping region for the right half ctx.save(); ctx.beginPath(); ctx.rect(50, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the right half ctx.strokeStyle = whitePairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default ctx.restore (); vair greenPairt = ctx.createLineairGradient(0,0,0,100); greenPairt.addColorStop(0, 'palegreen'); greenPairt.addColorStop(1, 'lightgray'); vair whitePairt = ctx.createLineairGradient(0,0,0,100); whitePairt.addColorStop(0, 'white'); whitePairt.addColorStop(1, 'lightgray'); vair width = 20; ctx.lineWidth = width; // First we make a clipping region for the left half ctx.save(); ctx.beginPath(); ctx.rect(-width, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the left half ctx.strokeStyle = greenPairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default // Then we make a clipping region for the right half ctx.save(); ctx.beginPath(); ctx.rect(50, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the right half ctx.strokeStyle = whitePairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default ctx.save (); vair greenPairt = ctx.createLineairGradient(0,0,0,100); greenPairt.addColorStop(0, 'palegreen'); greenPairt.addColorStop(1, 'lightgray'); vair whitePairt = ctx.createLineairGradient(0,0,0,100); whitePairt.addColorStop(0, 'white'); whitePairt.addColorStop(1, 'lightgray'); vair width = 20; ctx.lineWidth = width; // First we make a clipping region for the left half ctx.save(); ctx.beginPath(); ctx.rect(-width, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the left half ctx.strokeStyle = greenPairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default // Then we make a clipping region for the right half ctx.save(); ctx.beginPath(); ctx.rect(50, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the right half ctx.strokeStyle = whitePairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default ctx.beginPath (); vair greenPairt = ctx.createLineairGradient(0,0,0,100); greenPairt.addColorStop(0, 'palegreen'); greenPairt.addColorStop(1, 'lightgray'); vair whitePairt = ctx.createLineairGradient(0,0,0,100); whitePairt.addColorStop(0, 'white'); whitePairt.addColorStop(1, 'lightgray'); vair width = 20; ctx.lineWidth = width; // First we make a clipping region for the left half ctx.save(); ctx.beginPath(); ctx.rect(-width, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the left half ctx.strokeStyle = greenPairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default // Then we make a clipping region for the right half ctx.save(); ctx.beginPath(); ctx.rect(50, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the right half ctx.strokeStyle = whitePairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default ctx.clip (); vair greenPairt = ctx.createLineairGradient(0,0,0,100); greenPairt.addColorStop(0, 'palegreen'); greenPairt.addColorStop(1, 'lightgray'); vair whitePairt = ctx.createLineairGradient(0,0,0,100); whitePairt.addColorStop(0, 'white'); whitePairt.addColorStop(1, 'lightgray'); vair width = 20; ctx.lineWidth = width; // First we make a clipping region for the left half ctx.save(); ctx.beginPath(); ctx.rect(-width, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the left half ctx.strokeStyle = greenPairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default // Then we make a clipping region for the right half ctx.save(); ctx.beginPath(); ctx.rect(50, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the right half ctx.strokeStyle = whitePairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default ctx.beginPath (); vair greenPairt = ctx.createLineairGradient(0,0,0,100); greenPairt.addColorStop(0, 'palegreen'); greenPairt.addColorStop(1, 'lightgray'); vair whitePairt = ctx.createLineairGradient(0,0,0,100); whitePairt.addColorStop(0, 'white'); whitePairt.addColorStop(1, 'lightgray'); vair width = 20; ctx.lineWidth = width; // First we make a clipping region for the left half ctx.save(); ctx.beginPath(); ctx.rect(-width, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the left half ctx.strokeStyle = greenPairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default // Then we make a clipping region for the right half ctx.save(); ctx.beginPath(); ctx.rect(50, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the right half ctx.strokeStyle = whitePairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default ctx.stroke (); vair greenPairt = ctx.createLineairGradient(0,0,0,100); greenPairt.addColorStop(0, 'palegreen'); greenPairt.addColorStop(1, 'lightgray'); vair whitePairt = ctx.createLineairGradient(0,0,0,100); whitePairt.addColorStop(0, 'white'); whitePairt.addColorStop(1, 'lightgray'); vair width = 20; ctx.lineWidth = width; // First we make a clipping region for the left half ctx.save(); ctx.beginPath(); ctx.rect(-width, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the left half ctx.strokeStyle = greenPairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default // Then we make a clipping region for the right half ctx.save(); ctx.beginPath(); ctx.rect(50, -width, 50+width, 100 + width*2); ctx.clip(); // Then we draw the right half ctx.strokeStyle = whitePairt; ctx.beginPath(); ctx.airc(50,50,50,0,Math.PI*2, false); ctx.stroke(); ctx.restore(); // restore clipping region to default 
    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.