Draw line chart with connected dots using chartJS - Javascript Chart.js

Javascript examples for Chart.js:Line Chart

Description

Draw line chart with connected dots using 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.0/Chart.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//from   ww  w .  j a  va 2s  .c  o  m
var chart = new Chart(ctx, {
   type: 'scatter',
   data: {
      datasets: [{
         data: [{
            x: 1,
            y: 1
         }, {
            x: 3,
            y: 7
         }, {
            x: 6,
            y: 5
         }, { 
            x: 1,
            y: 1
         }],
         borderColor: 'black',
         borderWidth: 1,
         pointBackgroundColor: ['#000', '#00bcd6', '#d300d6'],
         pointBorderColor: ['#000', '#00bcd6', '#d300d6'],
         pointRadius: 5,
         pointHoverRadius: 5,
         fill: false,
         tension: 0,
         showLine: true
      }, {
         data: [{
            x: 3.5,
            y: 4.5
         }],
         pointBackgroundColor: 'orange',
         pointBorderColor: 'darkorange',
         pointRadius: 10,
         pointHoverRadius: 10
      }]
   },
   options: {
      legend: false,
      tooltips: false,
      scales: {
         xAxes: [{
            ticks: {
               min: 0,
               max: 10
            },
            gridLines: {
               color: '#888',
               drawOnChartArea: false
            }
         }],
         yAxes: [{
            ticks: {
               min: 0,
               max: 8,
               padding: 10
            },
            gridLines: {
               color: '#888',
               drawOnChartArea: false
            }
         }]
      }
   }
});
    }

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

Related Tutorials