I have 2 Google charts on my web page which are inside 2 separate items of a Bootstrap 3 Carousel. The chart that's on the active item (Slide 1) in the carousel shows up on the screen just fine however the chart that's not on the active list (Slide 2) doesn't show up even when the 2nd slide is active.
The relevant HTML is as follows:
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<div id="piechart" class="col-sm-6 col-md-6 col-lg-12" style="height: 500px;"></div>
</div>
<div class="item">
<div id="piecharts" class="col-sm-6 col-md-6 col-lg-12" style="height: 500px;"></div>
</div>
<div class="item">
<div id="piechartss" class="col-sm-6 col-md-6 col-lg-12" style="height: 500px;"></div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
and the JS is as follows:
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
alert('Helo');
var data = google.visualization.arrayToDataTable([
['CreditorName', 'Balance Amount'],
@For Each item In Model
@:['@item.CreditorName', @item.BalanceAmount],
Next
['Et', 0]
]);
var options = {
title: 'Creditors share in total debt.'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
for slide 2 I am not sure when to call it but right now I am using this:
$(document).ready(function () {
$('#carousel-example-generic').on('slide.bs.carousel', function () {
// do something…
loadCharInfo(this);
})
});
and the loadChartInfo is:
function loadChartInfo(carouselId)
{
//google.setOnLoadCallback(drawCharts);
google.load("visualization", "1", { packages: ["corechart"] });
var data1 = google.visualization.arrayToDataTable([
['Chart2Q', 'Amount'],
['Chart2-1', 10000],
['Chart2-2', 10000],
['Chart2-3', 10000]
]);
var options1 = {
title: 'Chart 2.'
};
var chart1 = new google.visualization.PieChart(document.getElementById('piecharts'));
chart1.draw(data1, options1);
}
I am pretty sure the chart 2 is being loaded properly as when I move the slide I can see a glimpse of the second chart as its in the process of sliding.