Customize Chart.js - Javascript Chart.js

Javascript examples for Chart.js:Chart Configuration

Description

Customize Chart.js

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>line chart with ChartJS</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.0.0-beta/Chart.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//w  ww. j  av  a  2  s. c om
var barChartData = {
  labels: ["January", "February", "March", "April", "May", "June", "July"],
  datasets: [{
    label: "My First dataset",
    data: [65, 50, 80, 81, 56, 85, 40],
  }]
}
var config = {
  type: 'bar',
  data: barChartData,
  scaleOverride: true,
  scaleStartValue: 0,
  options: {
    scales: {
      yAxes: [{
        ticks: {
           beginAtZero: true
        }
      }],
    },
    elements: {
      rectangle: {
        borderWidth: 2,
        borderColor: 'rgb(0, 255, 0)',
        borderSkipped: 'bottom'
      }
    },
    responsive: true,
    legend: {
      position: 'top',
    },
    title: {
      display: true,
      text: 'Chart.js Bar Chart'
    }
  }
};
var ctx = document.getElementById("myChart").getContext("2d");
new Chart(ctx, config);
    }

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

Related Tutorials