Links in bar charts for charts.js - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

Links in bar charts for charts.js

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Chart.js 2.0.0-beta Play</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){// ww  w  .  j  a  v  a2  s  .co  m
var data = [2137680, 6282693, 805566, 2568163, 598599, 3189284, 599112, 926340, 5548295, 11847685, 66445];
var labels = ["Management", "Finance", "Human Resources", "Business Development and Marketing", "Information Technology", "Professional Development and Training", "Knowledge Management", "Logistics", "Support", "Business Services", "Other"];
var bgColor = ["#878BB6", "#FFEA88", "#FF8153", "#4ACAB4", "#c0504d", "#8064a2", "#772c2a", "#f2ab71", "#2ab881", "#4f81bd", "#2c4d75"];
   var ctx = document.getElementById("myChart");
   var myChart = new Chart(ctx, {
      type: 'doughnut',
      data: {
            labels: labels,
            datasets: [
               {
                  data: data,
                  backgroundColor: bgColor
               }]
      }
   });
      document.getElementById("myChart").onclick = function(evt){
         var activePoints = myChart.getElementsAtEvent(evt);
         var firstPoint = activePoints[0];
         var label = myChart.data.labels[firstPoint._index];
         var value = myChart.data.datasets[firstPoint._datasetIndex].data[firstPoint._index];
         if (firstPoint !== undefined)
            console.log(label + ": " + value);
      };
    }

      </script> 
   </head> 
   <body> 
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.12.0/moment.min.js"></script> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.0.0-beta2/Chart.min.js"></script> 
      <canvas id="myChart" width="400" height="400"> 
      </canvas>  
   </body>
</html>

Related Tutorials