Chart.js pie chart with color settings - Javascript Chart.js

Javascript examples for Chart.js:Pie Chart

Description

Chart.js pie chart with color settings

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.5.0/Chart.js"></script> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//from   ww  w .  j a v  a2 s  .c o m
var pieData = {
  labels: [
  "Purple",
  "Green",
  "Orange",
  "Yellow"],
  datasets: [
    {
      data: [20, 40, 10, 30],
      backgroundColor: [
         "#878BB6",
         "#4ACAB4",
         "#FF8153",
         "#FFEA88"
      ]
  }]
};
var ctx = document.getElementById("myData").getContext("2d");
var myPieChart = new Chart(ctx, {
  type: 'pie',
  data: pieData
});
    }

      </script> 
   </head> 
   <body> 
      <h1>Chart.js Sample</h1> 
      <canvas id="myData" width="600" height="400"></canvas>  
   </body>
</html>

Related Tutorials