I have a situation where I try to use MorrisJS charts inside two different boot tabs . The chart loads fine on the first tab (by default), but when I click on the second tab, the chart does not load properly. This is very strange since I copy and paste the same as on the first and second tabs, but the second one does not load for me.
Here is a link to configure jsfiddle I. https://jsfiddle.net/phz0e68d/5/
Here is the code:
HTML:
<div> <ul class="nav nav-tabs" role="tablist"> <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li> <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li> </ul> <div class="tab-content"> <div role="tabpanel" class="tab-pane active" id="home"> <div class="row"> <div class="col-md-12"> <div id="chart1" style="height: 200px;"></div> </div> </div> </div> <div role="tabpanel" class="tab-pane" id="profile"> <div class="row"> <div class="col-md-12"> <div id="chart2" style="height: 200px;"></div> </div> </div> </div> </div> </div>
JavaScript:
Morris.Bar({ element: 'chart1', data: [ { y: '2006', a: 100, b: 90 }, { y: '2007', a: 75, b: 65 }, { y: '2008', a: 50, b: 40 }, { y: '2009', a: 75, b: 65 }, { y: '2010', a: 50, b: 40 }, { y: '2011', a: 75, b: 65 }, { y: '2012', a: 100, b: 90 } ], xkey: 'y', ykeys: ['a', 'b'], labels: ['Series A', 'Series B'], hideHover: 'always' }); Morris.Bar({ element: 'chart2', data: [ { y: '2006', a: 100, b: 90 }, { y: '2007', a: 75, b: 65 }, { y: '2008', a: 50, b: 40 }, { y: '2009', a: 75, b: 65 }, { y: '2010', a: 50, b: 40 }, { y: '2011', a: 75, b: 65 }, { y: '2012', a: 100, b: 90 } ], xkey: 'y', ykeys: ['a', 'b'], labels: ['Series A', 'Series B'], hideHover: 'always' });
The first graph is as follows:

The second graph is as follows:

As you can see, the second chart is not loading properly. There is an error in the console regarding negative width, but I'm not sure how this is possible.
