Single Point Curve via Chart.js - Javascript Chart.js

Javascript examples for Chart.js:Chart Configuration

Description

Single Point Curve via Chart.js

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  w w  w . j av  a 2s . c  o  m
var data = {
  xLabels: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
  yLabels: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
  datasets: [{
    label: '',
    data: [{
      x: -1,
      y: 7.1
    }, {
      x: 5,
      y: 6
    }, {
      x: 9,
      y: -1
    }],
    pointBackgroundColor: '#ffffff',
    borderColor: '#ffffff',
    pointStyle: 'rectRot',
    pointRadius: 8,
  }]
};
var options = {
  responsive: true,
  maintainAspectRatio: false,
  legend: {
    display: false,
  },
  layout: {
    padding: {
      left: 0,
      right: 0,
      top: 0,
      bottom: 0
    }
  },
  scales: {
    yAxes: [{
      position: 'left',
      ticks: {
        fontSize: 14,
        fontColor: '#a6a08f',
        fontFamily: 'Helvetica',
        fontStyle: 'bold',
        beginAtZero: true,
        min: 0,
        max: 7,
        stepSize: 1
      },
      gridLines: {
        color: '#a6a08f',
        drawTicks: true
      }
    }],
    xAxes: [{
      ticks: {
        fontSize: 14,
        fontColor: '#a6a08f',
        fontFamily: 'Helvetica',
        fontStyle: 'bold',
        beginAtZero: true,
        suggestedMin: 0,
        max: 10,
      },
      gridLines: {
        display: true,
        color: '#a6a08f',
        zeroLineColor: '#a6a08f',
        drawTicks: true
      }
    }]
  }
}
var ctx = document.getElementById('chart');
var chart = new Chart(ctx, {
  type: 'line',
  data: data,
  options: options
});
    }

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

Related Tutorials