update bar chart values - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

update bar chart values

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://code.jquery.com/jquery-2.1.3.js"></script> 
      <script type="text/javascript" src="https://rawgit.com/nnnick/Chart.js/f3eb6f4a433b4f34a582842dcf7b42f710861a7d/Chart.js"></script> 
      <script type="text/javascript">
    $(window).load(function(){/*from  ww w  . j  a va  2  s  . c om*/
var barChartData = {
    labels: [1, 2, 3, 4, 5, 6, 7],
    datasets: [{
        custom: true,
        label: "My First dataset",
        data: [0, 2, 3, 4, 5, 6, 7],
        backgroundColor: 'red'
    }, {
        label: "My Second dataset",
        data: [3, 4, 5, 6, 7, 1, 2],
        backgroundColor: 'blue'
    }]
};
var ctx = document.getElementById("chart").getContext("2d");
var my_chart = new Chart(ctx, {
    type: "bar",
    data: barChartData
});
$.each(my_chart.data.datasets, function (i, dataset) {
    dataset.metaData[3].custom = {
        backgroundColor: "green"
    };
    dataset.data[3] = 2.5;
});
my_chart.update();
    });

      </script> 
   </head> 
   <body> 
      <canvas id="chart" height="450" width="650"></canvas>  
   </body>
</html>

Related Tutorials