Chartjs-How to create a line on a chart using chartjs-plugin-annotation

1👍

You don’t actually need to set/use all the properties. Only set those which are needed to fulfill your requirement. So, setting the following properties should be enough to draw that horizontal line :

annotation: {
   annotations: [{
      type: 'line',
      id: 'hLine',
      mode: 'horizontal',
      scaleID: 'y-axis-0',
      value: 3,  // data-value at which the line is drawn
      borderWidth: 2,
      borderColor: 'black'
   }]
}

also, note that annotations property is not just an object, it­‘s an array of object(s).

Leave a comment