Chartjs-Inserting data from arrays into a pie chart (chart.js)

0👍

Please use the following jsfiddle , created for you, this might help you.

https://jsfiddle.net/ua5hsj7k/

<!DOCTYPE html>
<html>
<head>
<title>ChartJS - Pie</title>
<link type="text/css" rel="stylesheet" href="css/default.css" />
</head>
<body>
<div class="chart-container">
<div class="pie-chart-container">
  <canvas id="pie-chartcanvas-1"></canvas>
</div>


  </div>

   <!-- javascript -->
   <script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
  </body>
   </html>

# code in js file

    var piechart = $("#pie-chartcanvas-1");

   var data1 = {
   labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],
   datasets: [
   {
    label: "Population (millions)",
    backgroundColor: 
    ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
    data: [2478,5267,734,784,433]
     }
     ]
     };

   var chart = new Chart(piechart,{
   type:"pie",
   data : data1,
   options:{}
    })

Leave a comment