Setting Chart.js Pie-Graph Options - Javascript Chart.js

Javascript examples for Chart.js:Pie Chart

Description

Setting Chart.js Pie-Graph Options

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.0.0-beta/Chart.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//  ww  w.  ja  v a  2  s  . c  om
var randomScalingFactor = function()
{
    return Math.round(Math.random() * 100);
};
var randomColorFactor = function() {
    return Math.round(Math.random() * 255);
};
var randomColor = function(opacity) {
    return 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',' + (opacity || '.3') + ')';
};
var config =
{
    type: 'pie',
    data:
    {
        datasets:
        [
            {
                data:
                [
                    1, 2, 3, 5, 6
                ],
                backgroundColor:
                [
                    "#F7464A",
                    "#46BFBD",
                    "#FDB45C",
                    "#949FB1",
                    "#4D5360",
                ],
            }
        ],
        labels:
        [
            'A', 'B', 'C', 'D', 'E'
        ]
    },
    options:
    {
        elements: {
            arc: {
                borderColor: 'red'
            }
        }
    }
};
    var ctx = document.getElementById("chart-area").getContext("2d");
    window.myPie = new Chart(ctx, config);
    }

      </script> 
   </head> 
   <body> 
      <canvas id="chart-area" width="600" height="300"></canvas>  
   </body>
</html>

Related Tutorials