我试图让我的谷歌图表在他们点击标签链接后显示,但谷歌图表不显示。
我在里面包含了谷歌图表代码ChartlyDaily
。当它在ChartDaily
函数之外时它可以工作,但在它内部却没有。
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
function ChartDaily(){
google.setOnLoadCallback(drawChartDaily);
function drawChartDaily() {
var chart_data = ['3',7];
alert(chart_data);
var data = google.visualization.arrayToDataTable([
['Scoring Activity', 'Points given'], chart_data]);
var options = {
title: 'Semis overall scoring activity'
};
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
}
jQuery(document).ready(function() {
$('#tabs > div').hide();
$('#tabs div:first').fadeIn('slow');
$('#tabs ul li:first').addClass('active');
$('#tabs ul li a').click(function(){
$('#tabs ul li.active').removeClass('active'); // <== Only what you need
$(this).parent().addClass('active');
var selectedTab=$(this).attr('href');
$('#tabs > div').fadeOut('slow', function() { // <== Use a callback
$(selectedTab).delay(10).fadeIn('fast'); // <== add a delay
});
return false;
});
$('#menu_tab1').click(function(){
ChartDaily(); // supposed to show the chart
});
$('#menu_tab2').click(function(){
alert('tab-2 got clicked!!');
});
$('#menu_tab3').click(function(){
alert('tab-3 got clicked!!');
});
$('#menu_tab4').click(function(){
alert('tab-4 got clicked!!');
});
});
</script>
<div id="chart_div" style=" margin-left:-280px;width: 800px; height: 500px;"></div>