Accepted answer

update - this answer is for chart.js 1.x, if you are looking for a 2.x answer check the comments and other answers.

you extend the line chart and include logic for drawing the line in the draw function.


enter image description here


    <canvas id="linewithline" width="600" height="400"></canvas>


var data = {
    labels: ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"],
    datasets: [{
        data: [12, 3, 2, 1, 8, 8, 2, 2, 3, 5, 7, 1]

var ctx = document.getelementbyid("linewithline").getcontext("2d");

    name: "linewithline",
    draw: function () {
        chart.types.line.prototype.draw.apply(this, arguments);

        var point = this.datasets[0].points[this.options.lineatindex]
        var scale = this.scale

        // draw line
        this.chart.ctx.moveto(point.x, scale.startpoint + 24);
        this.chart.ctx.strokestyle = '#ff0000';
        this.chart.ctx.lineto(point.x, scale.endpoint);

        // write today
        this.chart.ctx.textalign = 'center';
        this.chart.ctx.filltext("today", point.x, scale.startpoint + 12);

new chart(ctx).linewithline(data, {
    datasetfill : false,
    lineatindex: 2

the option property lineatindex controls which point to draw the line at.

fiddle -


here's a pen that achieves a similar effect without the chartjs-plugin-annotation, or hacking how chart.js renders, or any other plugins:


  1. use a combo bar / line chart, and use the bar chart to draw the vertical lines.
  2. use two y-axes: one for the bar chart (which we don't display), and one for all your other line chart datasets.
  3. force the bar chart y-axes to min: 0 and max: 1. anytime you want to draw a vertical line, add a data object like { x: where_the_line_goes, y: 1 } to your bar chart dataset.
  4. the pen also adds some custom data to the bar chart dataset and a legend filter and label callback to exclude the bar chart dataset from the legend, and control the label on the vertical line.


  1. no other dependencies. no custom monkey patching / extending.
  2. the annotations plugin doesn't seem to be actively maintained. for instance, atm, their event handlers throw an error about "preventing default on passive events"
  3. maybe a pro: the annotations plugin always shows the labels of lines drawn, and you have to use their event callbacks to get a show-on-hover effect. chart.js tooltips show on hover by default.


  1. we're adding custom data in the dataset config, and hoping it doesn't conflict with anything chart.js is doing. it's data chart.js doesn't expect to be there, but as of 2.8, also doesn't break it.


i had to go through the trouble of figuring out how to do something similar with chartjs 2.0 so i thought i would share.

this is based on the new way of overriding a chart prototype as explained here:

var ctx = document.getelementbyid('income-chart');

var originaldraw = chart.controllers.line.prototype.draw;
chart.controllers.line.prototype.draw = function (ease) {, ease);

    var point = datavalues[vm.incomecentile];
    var scale = this.chart.scales['x-axis-0'];

    // calculate the portion of the axis and multiply by total axis width
    var left = (point.x / scale.end * (scale.right - scale.left));
    // draw line
    this.chart.chart.ctx.strokestyle = '#ff0000';
    this.chart.chart.ctx.moveto(scale.left + left, 0);
    this.chart.chart.ctx.lineto(scale.left + left, 1000000);

    // write label
    this.chart.chart.ctx.textalign = 'center';
    this.chart.chart.ctx.filltext('you', scale.left + left, 200);


i'd highly recommend to use the chartjs-plugin-annotation.

an example can be found at codepen

var chartdata = {
  labels: ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"],
  datasets: [
      data: [12, 3, 2, 1, 8, 8, 2, 2, 3, 5, 7, 1]

window.onload = function() {
  var ctx = document.getelementbyid("canvas").getcontext("2d");
  new chart(ctx, {
    type: "line",
    data: chartdata,
    options: {
      annotation: {
        annotations: [
            type: "line",
            mode: "vertical",
            scaleid: "x-axis-0",
            value: "mar",
            bordercolor: "red",
            label: {
              content: "today",
              enabled: true,
              position: "top"

have a look here for more details:


sharing my solution for version 2.5. i wanted to use a plugin, to make the implementation reusable.

const verticallineplugin = {
  getlineposition: function (chart, pointindex) {
      const meta = chart.getdatasetmeta(0); // first dataset is used to discover x coordinate of a point
      const data =;
      return data[pointindex]._model.x;
  renderverticalline: function (chartinstance, pointindex) {
      const lineleftoffset = this.getlineposition(chartinstance, pointindex);
      const scale = chartinstance.scales['y-axis-0'];
      const context = chartinstance.chart.ctx;

      // render vertical line
      context.strokestyle = '#ff0000';
      context.lineto(lineleftoffset, scale.bottom);

      // write label
      context.fillstyle = "#ff0000";
      context.textalign = 'center';
      context.filltext('my text', lineleftoffset, (scale.bottom - / 2 +;

  afterdatasetsdraw: function (chart, easing) {
      if (chart.config.lineatindex) {
          chart.config.lineatindex.foreach(pointindex => this.renderverticalline(chart, pointindex));


usage is simple then:

 new chart(ctx, {
     type: 'line',
     data: data,
     label: 'progress',
     options: options,
     lineatindex: [2,4,8],

the code above inserts red vertical lines at positions 2,4 and 8, running through points of first dataset at those positions.

Related Query

More Query from same tag