chartjs-plugin-streaming reverse

by Akihiko Kusanagi

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js"></script>
<canvas id="chart"></canvas>

JavaScript

var ctx = document.getElementById('chart').getContext('2d');
var chart = new Chart(ctx, {
  type: 'line',
  data: {
  	datasets: [{
    	data: [
      	{x: 1, y: 1},
      	{x: 2, y: 3},
      	{x: 3, y: 5},
      	{x: 4, y: 4},
      	{x: 5, y: 3}
      ]
    }, {
    	data: [
      	{x: 1, y: 3},
      	{x: 2, y: 2},
      	{x: 3, y: 1},
      	{x: 4, y: 3},
      	{x: 5, y: 5}
       ]
    }]
  },
  options: {
    scales: {
    	xAxes: [{
        type: 'time',
        ticks: {
        	display: true,
        	reverse: true
        }
    	}]
     },
    plugins: {
      streaming: {
        onRefresh: function(chart) {
          chart.data.datasets.forEach(function(dataset) {
            dataset.data.push({
              x: Date.now(),
              y: Math.random()
            });
          });
        }
      }
    }
  }
});