How to draw Horizontal line on Bar Chart Chartjs

后端 未结 2 833
灰色年华
灰色年华 2021-01-03 14:04

I have the following script of drawing bar chart and I wanna add horizontal line on particular y dot. I was trying following example link and I just substituted Chart

2条回答
  •  花落未央
    2021-01-03 14:29

    You can use Chart.js plugins to do that. Plugins let you handle specific events such as beforeUpdate or afterDraw and are also easy to implement :

    Chart.pluginService.register({
        afterDraw: function(chart) {
            // Code here will be triggered ... after the drawing
        }
    });
    

    An easy way to do it is to simply draw a line like you would you on a simple canvas element, after everything is drawn in your chart, using the lineTo method.


    Here is a small example (and its related code) of how it would look like :

提交回复
热议问题