ChartJS: chart showing all data - Javascript Chart.js

Javascript examples for Chart.js:Chart Data

Description

ChartJS: chart showing all data

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head> 
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css"> 
   </head> 
   <body translate="no"> 
      <div class="container"> 
         <canvas id="myChart" width="600" height="400"></canvas> 
      </div> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script> 
      <script>
      Chart.defaults.global.legend.display = false;
Chart.defaults.global.tooltips.enabled = false;
Chart.defaults.global.tooltips.displayColors = false;
var backgroundColor = ['rgba(255, 99, 132, 0.2)', 'rgba(54, 162, 235, 0.2)', 'rgba(255, 206, 86, 0.2)', 'rgba(75, 192, 192, 0.2)', 'rgba(153, 102, 255, 0.2)', 'rgba(255, 159, 64, 0.2)', 'rgba(255, 99, 132, 0.2)', 'rgba(54, 162, 235, 0.2)'];
var options = {/*from w  w  w  .  j  av  a2 s. c  o  m*/
   scales: {
      xAxes: [{
         display: false
      }],
     yAxes: [{
            ticks: {
                beginAtZero: true
            }
        }]
   }
};
var data = {
   labels: ["Brasil", "Argentina", "Chile", "Paraguai", "Peru", "B", "M"],
   datasets: [{
       data: [ 9.19, 7.77, 6.80, 6.23, 6.00, 4.00, 4.00 ],
       backgroundColor: backgroundColor
   }],
};
var ctx = $("#myChart");
var myChart;
function createChart(teste){
   if(myChart){
      myChart.destroy();
   }
   myChart = new Chart(ctx, {
      type: 'bar',
      data: teste,
      options: options,
   });
}
createChart(data);
      //# sourceURL=pen.js
    
      </script>  
   </body>
</html>

Related Tutorials