Skip to content

Instantly share code, notes, and snippets.

@cupOJoseph
Created December 29, 2021 03:19

Revisions

  1. cupOJoseph created this gist Dec 29, 2021.
    7 changes: 7 additions & 0 deletions chartjs-pie.markdown
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    ChartJS Pie
    -----------


    A [Pen](https://codepen.io/jschiarizzi/pen/LYzQPQb) by [Joseph Schiarizzi](https://codepen.io/jschiarizzi) on [CodePen](https://codepen.io).

    [License](https://codepen.io/jschiarizzi/pen/LYzQPQb/license).
    3 changes: 3 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    <div id="canvas-holder">
    <canvas id="chart-area"></canvas>
    </div>
    57 changes: 57 additions & 0 deletions script.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    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;
    };
    1 change: 1 addition & 0 deletions scripts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js"></script>
    4 changes: 4 additions & 0 deletions style.css
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    #canvas-holder canvas {
    width: 50vw !important;
    height: 50vw !important;
    }