Hide section in a Chart.js Pie Chart - Javascript Chart.js

Javascript examples for Chart.js:Pie Chart

Description

Hide section in a Chart.js Pie Chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Hide a data in Doughnut/Pie Datasets</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*w  w w  .  j  av  a  2s.c om*/
var ctx = document.getElementById("myDoughnut").getContext("2d");
var myChart = new Chart(ctx, {
    type: 'doughnut',
    data: {
        labels: ["Red", "Green", "Blue"],
        datasets: [{
            label: '# of Votes',
            data: [12, 19, undefined],
            backgroundColor: [
              '#f87979',
              '#79f879',
              '#7979f8'
            ],
            borderWidth: 5
        }]
    },
    options: {
      tooltips: {
        mode: null
      },
      plugins: {
        datalabels: {
          borderWidth: 5,
          borderColor: "white",
          borderRadius: 8,
          // color: 0,
          font: {
            weight: "bold"
          },
          backgroundColor: "lightgray"
        }
      }
    }
});
    }

      </script> 
   </head> 
   <body> 
      <div id="app"> 
         <div width="400"> 
            <canvas id="myDoughnut"></canvas> 
         </div> 
      </div> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js"></script> 
      <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@0.4.0/dist/chartjs-plugin-datalabels.js"></script> 
   </body>
</html>

Related Tutorials