How to place a text on morris.js bar graph

前端 未结 7 2925
無奈伤痛
無奈伤痛 2021-02-20 17:00

I have a morris.js bar graph. I want to place count on top of this graph. I looked into morris.js bar doc, could not find any.

On hover it should display

7条回答
  •  悲哀的现实
    2021-02-20 17:46

    I find better to pass via jQuery to an empty p

    This is the final result: Final Result

    This is my code:

    HTML

    JS Below the chart code. Remember to change theData variable to the one you're using in your code.

     var b=1;
       jQuery('rect').each(function (i) {
          $('p.num'+b).text(theData[i].value); 
          b++;
        });
    

    CSS

    .numero{
      text-align: center;
      font-size: 18px !important;
      font-weight: 600 !important;
    }
    

    I also have added a class to each color.

    Hope this helps anybody :) Happy coding!

提交回复
热议问题