Create and use Multiple charts in one page with chart.js - Javascript Chart.js

Javascript examples for Chart.js:Chart Configuration

Description

Create and use Multiple charts in one page with chart.js

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
      <meta http-equiv="X-UA-Compatible" content="ie=edge"> 
      <script src="https://code.jquery.com/jquery-3.3.1.js"></script> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.js"></script> 
      <title>Document</title> 
      <script>
        $(function () {/*from   w ww .  ja va2 s  . c o  m*/
            var ctx = document.getElementById("layanan").getContext('2d');
            var data = {
                datasets: [{
                    data: [10, 20, 30],
                    backgroundColor: [
                        '#3c8dbc',
                        '#f56954',
                        '#f39c12',
                    ],
                }],
                labels: [
                    'Request',
                    'Layanan',
                    'Problem'
                ]
            };
            var myDoughnutChart = new Chart(ctx, {
                type: 'doughnut',
                data: data,
                options: {
                    responsive: false,
                    maintainAspectRatio: false,
                    legend: {
                        position: 'bottom',
                        labels: {
                            boxWidth: 12
                        }
                    }
                }
            });
            var ctx_2 = document.getElementById("layanan_subbagian").getContext('2d');
            var data_2 = {
                datasets: [{
                    data: [10, 20, 30],
                    backgroundColor: [
                        '#3c8dbc',
                        '#f56954',
                        '#f39c12',
                    ],
                }],
                labels: [
                    'Request',
                    'Layanan',
                    'Problem'
                ]
            };
            var myDoughnutChart_2 = new Chart(ctx_2, {
                type: 'doughnut',
                data: data_2,
                options: {
                    responsive: false,
                    maintainAspectRatio: false,
                    legend: {
                        position: 'bottom',
                        labels: {
                            boxWidth: 12
                        }
                    }
                }
            });
        });
    
      </script> 
   </head> 
   <body> 
      <div> 
         <canvas id="layanan" width="240px" height="240px"></canvas> 
      </div> 
      <div> 
         <canvas id="layanan_subbagian" width="240px" height="240px"></canvas> 
      </div>  
   </body>
</html>

Related Tutorials