Json to bar chart - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

Json to 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://code.jquery.com/jquery-2.1.3.js"></script> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script> 
      <script type="text/javascript">
    $(window).load(function(){//from  ww  w  .  j  a va  2 s. c o  m
var data = {
         resultDescription: "SUCCESS",
         data: [["JAN","1048729"],["FEB","1220608"],["MAR","1299965"],["APR","1288644"],["MAY","1077342"],["JUN","705690"],["JUL","666131"],["AUG","769444"],["SEP","581618"],["OCT","564438"],["NOV","535066"],["DEC","1241228"]]};
var newArr = [];
var labelsArr = [];
var dataArr = [];
$.each(data.data,function(i,v){
    labelsArr.push(v[0]);
    dataArr.push(v[1]);
});
console.log(dataArr);
var datas = {
    labels: labelsArr,
    datasets: [
        {
            label: "My First dataset",
            fillColor: "rgba(220,220,220,0.2)",
            strokeColor: "rgba(220,220,220,1)",
            pointColor: "rgba(220,220,220,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(220,220,220,1)",
            data: dataArr
        },
    ]
};
   setTimeout(function() {
      var ctx = $("#barChart").get(0).getContext("2d");
      var myBarChart = new Chart(ctx).Bar(datas);
   }, 1500);
    });

      </script> 
   </head> 
   <body> 
      <canvas id="barChart" width="256" height="256"></canvas>  
   </body>
</html>

Related Tutorials