Sharing ideas

Solving problems

Gathering solutions

Exchanging thoughts

Ruby On Rails



Debian & Ubuntu
jQuery & CSS

Morris.js Display:none Workaround

Morris.js is great, simple and lightweight charts library powered by jQuery and Raphael. Unfortunately you may encounter an issue when you will try to plot a chart on element with display:none property – for example when using Twitter’s Bootstrap tabbed component – it just doesn’t render properly. So as a quick workaround you can fire-up after showing that element.

Bootstrap provides some neat javascript events that are fired after some specific actions. So when you dive in into documentation you will find out that you can catch shown even that is fired after the tab has been shown. Just like that:

$('a[data-toggle="tab"]').on('shown', function (e) { // activated tab
  e.relatedTarget // previous tab

Just create a simple snippet and you are good to go.