ui.newTab.index() gives you the index of the current tab, which is 2 in this case. However you are trying to access charts[index] and charts2[index], i.e. charts and charts2 which doesn’t exists as the length of both charts and charts2 is 1. Rendering chart1 and chart2 (or charts and charts2) on ‘tabsactivate’ should work fine in this case. Please take a look at this updated jsfiddle.
Still, if you are facing any issue please create a jsfiddle with sample data and share it with us so that we can understand your code better and help you out.