Time graph from JSON for line chart - Javascript Chart.js

Javascript examples for Chart.js:Line Chart

Description

Time graph from JSON for line chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Chart.js time graph and dates</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://npmcdn.com/chart.js@latest/dist/Chart.bundle.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){/*ww  w.  j a v  a 2  s  . co m*/
var input = [{"y":4,"x":"2017-01-01"},
             {"y":0,"x":"2017-01-02"},
             {"y":9,"x":"2017-01-03"},
             {"y":0,"x":"2017-01-04"},
             {"y":14,"x":"2017-01-05"}];
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
  type: "line",
  data: {
    datasets: [{
      "data": input,
       label: ["test"]
    }]
  },
  options: {
    "scales": {
      "xAxes": [{
        "type": "time"
      }]
    }
  }
});
    }

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

Related Tutorials