create More than 1 charts on same web page - Javascript Chart.js

Javascript examples for Chart.js:Chart Configuration

Description

create More than 1 charts on same web page

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>ChartJS Line Chart</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.3.0/Chart.js"></script> 
      <style id="compiled-css" type="text/css">

canvas {//from www  .j av a2  s  . c om
   background-color: #eee;
}


      </style> 
      <script type="text/javascript">
    window.onload=function(){
var optionsOne = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow"],
    datasets: [{
      label: 'Colors One',
      data: [7, 11, 5],
      borderWidth: 1
    }]
  },
  options: {
    scales: {
      xAxes: [{
        ticks: {
          display: true
        }
      }]
    }
  }
}
var optionsTwo = {
  type: 'line',
  data: {
    labels: ["Green", "Purple", "Orange"],
    datasets: [{
      label: 'Colors Two',
      data: [8, 3, 7],
      borderWidth: 1
    }]
  },
  options: {
    scales: {
      xAxes: [{
        ticks: {
          display: true
        }
      }]
    }
  }
}
var ctxOne = document.getElementById('chartOneContainer').getContext('2d');
new Chart(ctxOne, optionsOne);
var ctxTwo = document.getElementById('chartTwoContainer').getContext('2d');
new Chart(ctxTwo, optionsTwo);
    }

      </script> 
   </head> 
   <body>  
      <canvas id="chartOneContainer" width="600" height="400"></canvas> 
      <br> 
      <canvas id="chartTwoContainer" width="600" height="400"></canvas>   
   </body>
</html>

Related Tutorials