Set chart js data-point between bar charts - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

Set chart js data-point between bar charts

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>chart.js annotation plugin (time xAxes)</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.0/Chart.min.js"></script> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-annotation/0.5.5/chartjs-plugin-annotation.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//from  w ww  . j a  va2 s.  c  om
var ann = ['2018-02-02', '2018-02-05', '2018-02-12'];
var ann_values = ['0123456789abcde', 40, 90];
var annotations_array = ann.map(function(date, index) {
   return {
      type: 'line',
      id: 'vline' + index,
      mode: 'vertical',
      scaleID: 'x-axis-0',
      value: date,
      borderColor: 'green',
      borderWidth: 1,
      label: {
         enabled: true,
         position: "center",
         content: ann_values[index]
      }
   }
});
var chart = new Chart(ctx, {
   type: 'line',
   data: {
      labels: ['2018-02-02', '2018-02-05', '2018-02-09', '2018-02-12', '2018-02-14', '2018-02-18'],
      datasets: [{
         label: 'LINE',
         data: [6, 2, 7, 4, 8, 9],
         backgroundColor: 'rgba(0, 100, 100, 0.2)',
         borderColor: 'rgba(0, 100, 200, 0.8)'
      }]
   },
   options: {
         legend: {display: false},
    layout: {
        padding: {
            left: 50,
            right: 50,
            top: 0,
            bottom: 0
        }
    },
      scales: {
         yAxes: [{
            ticks: {
               beginAtZero: false,
            }
         }],
        xAxes: [{
           type: 'time',
           source: 'labels',
          time: {
             min: '2018-01-30',
            unit: 'day'
          }
        }]
      },
      annotation: {
         drawTime: 'afterDatasetsDraw',
         annotations: annotations_array,
      }
   }
});
    }

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

Related Tutorials