A Pen by Caleb Miller on CodePen.
Created
November 10, 2023 09:22
-
-
Save luke-au/3123a8972bf3e667c0c342ff11d68dab to your computer and use it in GitHub Desktop.
Chart.js Gradients
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<canvas id="bar-chart" width="400" height="300"></canvas> | |
<!-- <canvas id="line-chart" width="400" height="400"></canvas> --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Chart.defaults.global.elements.rectangle.backgroundColor = '#FF0000'; | |
var bar_ctx = document.getElementById('bar-chart').getContext('2d'); | |
var purple_orange_gradient = bar_ctx.createLinearGradient(0, 0, 0, 600); | |
purple_orange_gradient.addColorStop(0, 'orange'); | |
purple_orange_gradient.addColorStop(1, 'purple'); | |
var bar_chart = new Chart(bar_ctx, { | |
type: 'bar', | |
data: { | |
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"], | |
datasets: [{ | |
label: '# of Votes', | |
data: [12, 19, 3, 8, 14, 5], | |
backgroundColor: purple_orange_gradient, | |
hoverBackgroundColor: purple_orange_gradient, | |
hoverBorderWidth: 2, | |
hoverBorderColor: 'purple' | |
}] | |
}, | |
options: { | |
scales: { | |
yAxes: [{ | |
ticks: { | |
beginAtZero:true | |
} | |
}] | |
} | |
} | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.0/Chart.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
canvas { | |
display: block; | |
max-width: 800px; | |
margin: 60px auto; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment