Updating chart.js bar chart in real time - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

Updating chart.js bar chart in real time

Demo Code

ResultView the demo in separate window


<html>
   <head></head>
   <body> 
      <canvas id="myChart" width="400" height="400"></canvas> 
      <script src="http://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script> 
      <script type="text/javascript">
    var ctx = document.getElementById("myChart").getContext("2d");
    var data = {// w w  w  .  j  a  v  a  2s  .  com
        labels: ["IBM", "Microsoft"],
        datasets: [{
            label: "Product A",
            fillColor: "rgba(220,220,220,0.5)",
            strokeColor: "rgba(220,220,220,0.8)",
            data: [25, 75]
        }, {
            label: "Product B",
            fillColor: "rgba(151,187,205,0.5)",
            strokeColor: "rgba(151,187,205,0.8)",
            data: [75, 25]
        }]
    }
    var myBarChart = new Chart(ctx).Bar(data);
    setTimeout(function(){
      myBarChart.addData([40, 60], "Google");
    },1000);
    
      </script> 
      <script>
console.log(10);

      </script>  
   </body>
</html>

Related Tutorials