[Chartjs]-Chart.js add second line in a Line chart that starts from end of first line

2👍

Yes, you can use object notation like so:

const options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
        label: '# of Votes',
        data: [{
          x: "Red",
          y: 5
        }, {
          x: "Blue",
          y: 3
        }, {
          x: "Yellow",
          y: 8
        }],
        borderColor: 'pink'
      },
      {
        label: '# of Points',
        data: [{
          x: "Yellow",
          y: 8
        }, {
          x: "Green",
          y: 5
        }, {
          x: "Purple",
          y: 3
        }, {
          x: "Orange",
          y: 8
        }],
        borderColor: 'orange'
      }
    ]
  },
  options: {}
}

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/3.5.1/chart.js"></script>
</body>

Leave a comment