Javascript examples for Chart.js:Pie Chart
Strike though labels when data is hidden for pie chart
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="https://code.jquery.com/jquery-2.2.4.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.js"></script> <style id="compiled-css" type="text/css"> .text-center {//from w w w .j a va 2 s. co m text-align: center; } </style> <script type="text/javascript"> window.onload=function(){ var ctx = document.getElementsByClassName('rscWeightChart'); if (ctx.length > 0) { for (i = 0; i < ctx.length; i++) { var id = ctx[i].getAttribute('id'); var rscWeightChart = new Chart(ctx, { type: 'pie', fill: true, data: { labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"], datasets: [{ label: '# of Votes', data: [12, 19, 3, 5, 2, 3], borderWidth: 1 }, ]}, options: { animation: { animateScale: true }, legend: { position: 'bottom', } } }); rscWeightChart.resize(); } $('.toggleLegend').click(function (button) { button.preventDefault(); rscWeightChart.getDatasetMeta(0).data.forEach(function (ds) { ds.hidden = !ds.hidden; }); rscWeightChart.update(); }); } } </script> </head> <body> <h2 class="text-center">Uitgaand totaalgewicht per stroom</h2> <canvas id="rscWeightChart" class="rscWeightChart" width="100" height="25"> </canvas> <div class="row"> <button id="toggleLegend" class="btn btn-sm btn-primary center-block toggleLegend">Toggle dataset </button> </div> </body> </html>