我有以下页面(请看下面),带有 Bootstrap 4 和 Google 图表。
有 3 个黑匣子,右边的有 google chart pie。我遇到的问题是图表使用的区域与实际图表相比太大了。
所以我用这个大小配置图表:
div id="piechart_3d" style="width: 500px; height: 250px;"></div>
但正如您所看到的,它占用了所有空间,但图表实际上是该 div 使用的区域大小的一半。
有什么方法可以配置它以减少该 div 使用的区域,但增加图表的大小以使用 500px x 250px 的大部分空间?
谢谢
<!DOCTYPE html> <html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load("current", { packages: ["corechart"] });
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 60],
['Eat', 20],
['Watch TV', 10],
['Sleep', 10]
]);
var options = {
//title: 'My Daily Activities',
backgroundColor: '#343a40',
colors: ['#2F5499', '#3965B8', '#708CCE', '#4A6BAD'],
is3D: true,
};
var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
chart.draw(data, options);
}
</script>
</head>
</head>
<body>
<style>
.card-body {
padding: 0.01rem
}
.padding-header {
padding: 0.6rem
}
.bg-light-blue {
background-color: #4671C3;
}
.bg-lila {
background-color: #6F339F;
}
.bg-dark {
background-color: #424242;
}
.black-box-size {
max-width: 100%;
height: 300px;
}
.shape-round {
height: 150px;
width: 150px;
background-color: #6F339F;
border-radius: 50%;
display: inline-block;
text-align: center;
color: #fff;
padding: 3.5rem 1.5rem;
}
.block-container {
position: absolute;
top: 40%;
left: 50%;
-moz-transform: translateX(-50%) translateY(-50%);
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
width: 109px;
height: 38px;
}
</style>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<h2 class="padding-header bg-light-blue text-white">Opportunity Breakdown (Sat)</h2>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="row">
<div class="col-md-11">
<div class="black-box-size bg-dark text-white">
<div>
<h2 class="text-center padding-header">Today</h2>
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
</div>
</div>
</div>
<div class="col-md-1">
</div>
</div>
</div>
<div class="col-md-4">
<div class="black-box-size bg-dark text-white">
<div>
<h2 class="text-center padding-header">This Week</h2>
</div>
</div>
</div>
<div class="col-md-4">
<div class="row">
<div class="col-md-1">
</div>
<div class="col-md-11">
<div class="black-box-size bg-dark text-white">
<div>
<h2 class="text-center padding-header">This Month</h2>
<div >
<div id="piechart_3d" style="width: 500px; height: 250px;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p></p>
</div>