[Chartjs]-Chart Js V2 draw Horizontal Bar(Average) Over Vertical Bar

4👍

You can add a plugin to your chart which can draw anything you’d like on the chart, for example a green line. You can read about plugins in the documentation for ChartJS. Since you want the green line to appear above the vertical bars, you should use the afterDraw method.

Once you’ve set the plugin up, the steps to accomplish this would be:

  1. Calculate the mean of all the bars in your chart (sum them up and divide by the number of bars)
  2. From the previous calculation: Decide the Y position of the line and based on that, draw the green line on the canvas.

Check out CanvasRenderingContext2D if you are new to how the browser canvas works.

Leave a comment