我正在尝试在同一网页上加载饼图和仪表。当我打开网页时,它只显示3个仪表,而且它没有显示饼图。 我已经按照google的建议将核心图表和仪表添加到一个加载器中。
<html>
<head>
<script type="text/javascript"
src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', { packages: ['corechart', 'gauge'] });
google.charts.setOnLoadCallback(drawChartb);
google.charts.setOnLoadCallback(drawChart);
function drawChartb() {
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Port 1', 70],
['Port 2', 70],
['Port 3', 70]
]);
var options = {
width: 400, height: 120,
redFrom: 90, redTo: 100,
yellowFrom:75, yellowTo: 90,
minorTicks: 5
};
var chart = new google.visualization.Gauge(document.getElementById('chart_div'));
chart.draw(data, options);
setInterval(function() {
data.setValue(0, 1, window.Power_chart1.Port1P);
data.setValue(1, 1, window.Power_chart1.Port2P);
data.setValue(2, 1, window.Power_chart1.Port3P);
chart.draw(data, options);
}, 1000);
}
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Port 1', 10],
['Port 2', 10],
['Port 3', 10]
]);
var options = {
title: 'Pie Chart Input Ports',
pieHole: 0.4,
};
var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
chart.draw(data, options);
setInterval(function() {
data.setValue(2, 1, window.Power_chart1.Port3P);
data.setValue(1, 1, window.Power_chart1.Port2P);
data.setValue(0, 1, window.Power_chart1.Port1P);
chart.draw(data, options);
}, 1000);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 400px; height: 120px;"></div>
</body>
</html>
谢谢;
答案 0 :(得分:1)
document.getElementById('donutchart')用于渲染饼图,但缺少元素。因此它不会被渲染。 包括以下内容
<div id="donutchart" style="width: 400px; height: 120px;"></div>
codepen - http://codepen.io/pen/