A Pen by Joseph Schiarizzi on CodePen.
Created
December 29, 2021 03:20
-
-
Save cupOJoseph/2be4344b2b57ab2126b10f23b1bae54d to your computer and use it in GitHub Desktop.
ChartJS Pie
This file contains hidden or 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
<div id="canvas-holder"> | |
<canvas id="chart-area"></canvas> | |
</div> |
This file contains hidden or 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
var randomScalingFactor = function() { | |
return Math.round(Math.random() * 100); | |
}; | |
var config = { | |
type: 'pie', | |
data: { | |
datasets: [{ | |
data: [ | |
53, | |
20, | |
15, | |
8, | |
4, | |
], | |
backgroundColor: [ | |
'#8EB5F0', | |
'#3A79AB', | |
'#3265D3', | |
'#3D4273', | |
'#598BFE', | |
], | |
label: 'Contratos' | |
}], | |
labels: [ | |
'DAO Treasury [Reserve]', | |
'Mainnet Airdrop', | |
'Member Airdrop', | |
'DAO Treasury [Liquidity Incentives]', | |
'DAO Treasury [Artist Rewards]' | |
] | |
}, | |
options: { | |
responsive: true, | |
maintainAspectRatio: false, | |
legend: { | |
fullWidth: false, | |
onClick(e, {index}) { | |
alert(index); | |
} | |
}, | |
layout: { | |
padding: 0 | |
} | |
} | |
}; | |
var chart; | |
window.onload = function() { | |
var ctx = document.getElementById('chart-area').getContext('2d'); | |
chart = new Chart(ctx, config); | |
chart.canvas.parentNode.style.width = '100vw'; | |
chart.canvas.parentNode.style.height = '100vw'; | |
window.myPie = chart; | |
}; |
This file contains hidden or 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.8.0/Chart.min.js"></script> |
This file contains hidden or 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-holder canvas { | |
width: 50vw !important; | |
height: 50vw !important; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment