plot JSON to chartJS - Javascript Chart.js

Javascript examples for Chart.js:Chart Json Data

Description

plot JSON to chartJS

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.7.1/Chart.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//from www .  ja v a  2  s .c  o  m
var prices = [{"close":0.00786609},{"close":0.00784},{"close":0.00784},
 {"close":0.00780507},{"close":0.007816},{"close":0.00781599},
 {"close":0.00780166},{"close":0.00778403},{"close":0.00782001},
 {"close":0.0078},{"close":0.00778},{"close":0.007799},
 {"close":0.00775057},{"close":0.0077688},{"close":0.00775001}];
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
    // The type of chart we want to create
    type: 'line',
    // The data for our dataset
    data: {
        datasets: [{
            label: "My First dataset",
            backgroundColor: 'rgb(255, 99, 132)',
            borderColor: 'rgb(255, 99, 132)',
            data: prices.map(function (price) {
               return price.close;
            }),
        }]
    },
    // Configuration options go here
    options: {}
});
    }

      </script> 
   </head> 
   <body> 
      <canvas id="myChart"></canvas>  
   </body>
</html>

Related Tutorials