这是带有标签的谷歌图表的完整工作示例
<script type="text/javascript" src="https://www.google.com/jsapi?ext.js"></script>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
google.load('visualization', '1.0', {'packages':['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]);
var data1 = google.visualization.arrayToDataTable([
['Tasks', 'Hours per Day'],
['Works', 12],
['Eats', 20],
['Commutes', 21],
['Watch TVs', 12],
['Sleeps', 17]
]);
var options = {'title':'Score Chart',
'width':600,
'height':300};
$(".tabs a[title='content_2']").click()
$(".tabs a[title='content_1']").click()
var chart = new google.visualization.BarChart(document.getElementById('chart'));
chart.draw(data, options);
var chart1= new google.visualization.BarChart(document.getElementById('chart1'));
chart1.draw(data1, options);
}
// When the document loads do everything inside here ...
$(document).ready(function(){
// When a link is clicked
$("a.tab").click(function () {
// switch all tabs off
$(".active").removeClass("active");
// switch this tab on
$(this).addClass("active");
// slide all content up
$(".content").slideUp();
// slide this content up
var content_show = $(this).attr("title");
$("#"+content_show).slideDown();
});
});
</script>
<body>
<div id="tabbed_box_1" class="tabbed_box">
<br />
<div class="tabbed_area">
<ul class="tabs">
<li><a href="#" title="content_1" class="tab active">Tab1</a></li>
<li><a href="#" title="content_2" class="tab">Tab2</a></li>
<li><a href="#" title="content_3" class="tab">Tab3</a></li>
</ul>
<div id="content_1" class="content">
<div id="chart"></div>
</div>
<div id="content_2" class="content">
<div id="chart1"></div>
</div>
<div id="content_3" class="content">
<ul>
<li><a href="">Home</a></li>
<li><a href="">About</a></li>
</ul>
</div>
</div>