我有以下css将google图表api放在仪表图的中心:
.chart {
display: block;
margin: 0 auto;
width: 100%;
max-width: 1000px;
max-height: 400px;
}
在html中,我有:
<div class="text-center">
<div class="chart" id="gauge"></div>
</div>
图表通过函数调用显示:
function getGaugeChart(value) {
var data = new google.visualization.arrayToDataTable([
['Label', 'Value'],
['Gauge', value]
]);
var options = {
width: 1200, height: 360,
redFrom: 0, redTo: 10,
yellowFrom: 10, yellowTo: 25,
greenFrom: 90, greenTo: 100,
minorTicks: 5
};
var chart = new google.visualization.Gauge(document.getElementById('gauge'));
chart.draw(data, options);
}