score:0

you can use a custom plugin for this:

const customline = {
  id: 'customline',
  beforedatasetsdraw: (chart, args, options) => {
    const {
      ctx,
      scales: {
        x,
        y
      }
    } = chart;

    chart.data.datasets[0].data.foreach((datapoint, i) => {

      ctx.strokestyle = options.linecolor || 'black';
      ctx.linewidth = options.linewidth || 1;

      ctx.beginpath();
      ctx.moveto(x.getpixelforvalue(chart.data.labels[i]), y.getpixelforvalue(datapoint));
      ctx.lineto(x.getpixelforvalue(chart.data.labels[i]), y.getpixelforvalue(chart.data.datasets[1].data[i]));
      ctx.stroke();

    })

  }
}

var options = {
  type: 'line',
  data: {
    labels: ["red", "blue", "yellow", "green", "purple", "orange"],
    datasets: [{
        label: '# of votes',
        data: [12, 19, 3, 5, 2, 3],
        borderwidth: 1,
        showline: false,
        backgroundcolor: 'red'
      },
      {
        label: '# of points',
        data: [7, 11, 5, 8, 3, 7],
        borderwidth: 1,
        showline: false,
        backgroundcolor: 'blue'
      }
    ]
  },
  options: {
    plugins: {
      customline: {
        linecolor: 'pink',
        linewidth: 3
      }
    }
  },
  plugins: [customline]
}

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


Related Query

More Query from same tag