Change chart.js color fill and y axes in bar chart - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

Change chart.js color fill and y axes in bar chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.js"></script> 
      <script type="text/javascript">
    window.onload=function(){/*from   w  w w. ja v a  2s . c o m*/
var canvas = document.getElementById('updating-chart'),
    ctx = canvas.getContext('2d'),
    startingData = {
      labels: ["A", "B", "C", "D"],
      datasets: [
          {
             label: "Product A",
             backgroundColor:"rgba(206, 70, 90, 1)",
             fillColor: "rgba(206, 70, 90, 1)",
             strokeColor: "rgba(220,220,220,0.8)",
              pointColor: "rgba(220,220,220,1)",
              pointStrokeColor: "#fff",
              data: [65, 59, 80, 81],
              options: {
              scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero:true,
                        min: 0,
                        max: 10
                    }
                  }]
               }
            }
          }
      ]
    };
var myLiveChart = new Chart(ctx,{
  type: 'bar',
  data: startingData,
  responsive: true,
  maintainAspectRatio: true
});
setInterval(function(){
  var indexToUpdate = Math.round(Math.random() * startingData.labels.length);
  myLiveChart.data.datasets[0].data[indexToUpdate] = Math.random() * 100;
  myLiveChart.update();
}, 500);
    }

      </script> 
   </head> 
   <body> 
      <canvas id="updating-chart" width="640" height="480"></canvas>  
   </body>
</html>

Related Tutorials