I have a page with Bootstrap (v3) tabs:
https://getbootstrap.com/docs/3.3/javascript/#tabs
I have some Sparkline graphs rendered in each tab:
https://omnipotent.net/jquery.sparkline/#s-docs
and called like this:
$('.sparkline-pie-remaining').sparkline('html', {
type: 'pie',
sliceColors: ['#1ab394', '#ed5565','#ddd'],
width: '18',
height: '18',
offset: -90,
disableTooltips: true,
borderWidth: 1,
borderColor: '#676a6c'
});
The issue is that this does not get called on the inactive tabs. There is a callback which I tried for when the tab is shown but then it calls this each time the tabs change and the graphs are cleared out.
How do I get this call to happen on the inactive tab content when the page is rendered? Here is a CodePen to reproduce the issue:
The reason why the Sparkline graph is not rendered inside the inactive tabs is because that tabpanel div has "display:none" attribute. Here's a section from the documentation you provided (see "Hidden Sparklines" section):
The solution is also included in the same quoted text. You can achieve this by attaching an event handler on either the tab button or the tabpanel div and by calling
$.sparkline_display_visible()
when the tab becomes active for the first time.EDIT: You can test this quickly by making the tab active and executing
$.sparkline_display_visible()
once in the JS console.