Chartjs-Is it possible to draw a line chart in chart.js with multiple lines and **multiple lables**

0👍

You can add a second X axis for your other labels:

const xValues1 = [50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150];
const yValues1 = [7, 8, 8, 9, 9, 9, 10, 11, 14, 14, 15];

const xValues2 = [54, 64, 74, 84, 94, 104, 114, 124, 134, 144, 154];
const yValues2 = [8, 9, 9, 10, 10, 10, 11, 12, 15, 15, 16];

const options = {
  type: 'line',
  data: {
    datasets: [{
        label: '# of Votes',
        data: yValues1,
        borderColor: 'pink'
      },
      {
        label: '# of Points',
        data: yValues2,
        borderColor: 'orange',
        xAxisID: 'x2' // Match dataset to other axis
      }
    ]
  },
  options: {
    scales: {
      xAxes: [{
          type: 'category',
          labels: xValues1,
          id: 'x',
          display: true // Set to false to hide the axis
        },
        {
          type: 'category',
          labels: xValues2,
          id: 'x2',
          display: true // Set to false to hide the axis
        }
      ]
    }
  }
}

const ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>
</body>

Leave a comment