我正在使用Twitter引导程序创建包含选项卡的页面。并希望在每个标签内容中添加谷歌图表。但是当我运行应用程序时,图表在宽度和高度上采用了不同的大小,尽管我在每个图表中使用内联css提到了宽度和高度。我该如何解决这个问题?如有任何想法请与我分享。您可以在此处查看我的代码:http://www.bootply.com/ddPRHKy8ey
<head>
<script src="/assets/jquery-1.10.2.js"></script>
<script src="/assets/bootstrap.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {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 options = {
title: 'My Daily Activities',
is3D: true,
};
var chart = new google.visualization.PieChart(document.getElementById('google_chart1'));
chart.draw(data, options);
}
</script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {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 options = {
title: 'My Daily Activities',
is3D: true,
};
var chart = new google.visualization.PieChart(document.getElementById('google_chart2'));
chart.draw(data, options);
}
</script>
<body>
<section>
<div class="container">
<div class="row">
<div class="col-md-3">
<div class="well well-lg">
<ul id="myTab" class="nav nav-pills nav-stacked">
<li class="active"><a href="#panel_conservative" data-toggle="tab">Side Tab 1</a></li>
<li><a href="#panel_mconservative" data-toggle="tab">Side Tab 2</a></li>
</ul>
</div>
</div>
<div class="col-md-9">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade in active" id="panel_conservative">
<div class="col-sm-12">
<div class="panel panel-default">
<ul id="myTab1" class="nav nav-pills nav-justified">
<li class="active"><a href="#cons18" data-toggle="tab">Tab NO 1</a></li>
<li><a href="#cons31" data-toggle="tab">Tab NO 2</a></li>
</ul>
<div class="panel-heading">
<div id="myTabContent1" class="tab-content">
<div class="tab-pane fade in active" id="cons18">
<div class="row">
<div class="col-sm-8">
<div class="row pad_right">
<div id="google_chart1" style="width: 500px;height: 300px;"></div>
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="cons31">
<div class="row">
<div class="col-sm-8">
<div class="row pad_right">
<div id="google_chart2" style="width: 500px;height: 300px;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="panel_mconservative">
content of side tab 2
</div>
</div>
</div>
</div>
</div>
</section>
答案 0 :(得分:7)
得到了ryenus的解决方案。 谢谢他。 Why are Bootstrap tabs displaying tab-pane divs with incorrect widths when using highcharts?
请查看updated solution。
答案 1 :(得分:0)
将宽度和高度作为选项传递
var options = {
title: 'My Daily Activities',
is3D: true,
width: 500,
height: 300
};