Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gradient to bar chart and pie chart #166

Closed
MobileMon opened this issue Jan 15, 2020 · 10 comments
Closed

Add gradient to bar chart and pie chart #166

MobileMon opened this issue Jan 15, 2020 · 10 comments
Labels

Comments

@MobileMon
Copy link

Instead of a solid color, can I use a gradient to fill in the pie chart segments and bar chart segments?

@imaNNeo imaNNeo added Bar Chart enhancement New feature or request Pie Chart labels Jan 16, 2020
@xi1570-krupeshanadkat
Copy link

Yes, I want to add gradient in bar graph rods. please add this feature.

@imaNNeo
Copy link
Owner

imaNNeo commented Mar 27, 2020

What kind of gradient do you need in the PieChart?
@MobileMon

@bdairy
Copy link

bdairy commented Jun 2, 2020

to use gradient colors like this
image

@imaNNeo imaNNeo mentioned this issue Oct 6, 2020
@imaNNeo
Copy link
Owner

imaNNeo commented Oct 6, 2020

It has just been added in 0.12.0 version.

Check out this sample

The pie chart gradient is yet to come!

@Nirsu
Copy link

Nirsu commented Sep 16, 2021

Hello guys,
I didn't want to open a new issue, since this one was still open.
I would like to know if there was any information about the gradient for pie charts, because I would like to make a gradient like that:
image

@asaboor-art
Copy link

Screenshot 2022-08-19 234656
i want this type of gradient color design in Doughnut Chart.. can someone help me?

@asaboor-art
Copy link

<script> const settings = { canvasId : 'canvas', fillAmount : 85, baseAmount : 100, fillColor : '#64c832', baseColor : '#EBF5FB', lineWidth : 20, } const state = { curAmount: 0, curDegrees: 0 } const canvas = document.getElementById(settings.canvasId) canvas.halfWidth = canvas.width / 2 canvas.halfHeight = canvas.height / 2 const ctx = canvas.getContext('2d') animate() function animate () { update() draw() if (state.curAmount < settings.fillAmount) { requestAnimationFrame(animate) } } function update () { state.curAmount += 1 state.curDegrees = (state.curAmount / settings.baseAmount) * 360 } function draw () { ctx.clearRect(0, 0, canvas.width, canvas.height) drawArc(0, 360, settings.baseColor) drawArc(-90, (state.curDegrees - 90), settings.fillColor) drawText(state.curAmount) } function drawArc (startDegrees, endDegrees, lineColor) { ctx.lineWidth = settings.lineWidth ctx.strokeStyle = lineColor ctx.beginPath() ctx.arc( canvas.halfWidth, canvas.halfHeight, canvas.halfWidth - (settings.lineWidth / 2), degreesToRadians(startDegrees), degreesToRadians(endDegrees) ) ctx.stroke() } function drawText (text) { ctx.fillStyle = settings.fillColor ctx.font = 'bold ' + settings.fontSize + ' ' + settings.fontFace ctx.textAlign = 'center' ctx.fillText( text, canvas.halfWidth, canvas.halfHeight + (parseInt(settings.fontSize) / 3) ) } function degreesToRadians (degrees) { return degrees * Math.PI / 180 } document.getElementById('replay').addEventListener('click', function() { state.curAmount = 0 state.curDegrees = 0 animate() }) </script>
<div id="canvas-wrap">
            <canvas id="canvas" width="300" height="300"></canvas>
            <div class="donut-result">
               <p><span>9,8969</span> Estimated Overtime Owed</p>
             </div>
          </div>
          
          #canvas-wrap {display: flex;justify-content: center;align-items: center;width: 100%;height: 100%;}

@raldhafiri
Copy link

I have created pull request
#1511

it will add support for piechart gradients

@imaNNeo
Copy link
Owner

imaNNeo commented Dec 25, 2023

PieChart gradient is added in 0.66.0.
Thanks, @raldhafiri for contributing 🚀

@imaNNeo
Copy link
Owner

imaNNeo commented Dec 25, 2023

It has just been added in 0.12.0 version.

Check out this sample

The pie chart gradient is yet to come!

I think now we're done with this issue ;)

@imaNNeo imaNNeo closed this as completed Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants