我有以下使用谷歌饼图的代码,但是饼图预先填充了数据,我希望通过一些带有 HTML 的基本文本表单来获取用户输入,但是我不确定如何更改默认活动“
['Work', 8],
['Friends', 2],
['Eat', 2],
['TV', 3],
['Gym', 2],
['Sleep', 7]"
是用户输入的内容,而不是如图所示的预设内容。
<html>
<head>
<!--bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- jQuery (CDN)-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- google api of the pi chart -->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<!-- Angular -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script type="text/javascript">
// Load google charts
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
// Draw the chart and set the chart values
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 8],
['Friends', 2],
['Eat', 2],
['TV', 3],
['Gym', 2],
['Sleep', 7]
]);
// Optional; add a title and set the width and height of the chart
var options = {'title':'Time Spent', 'width':700, 'height':500};
// Display the chart inside the <div> element with id="piechart"
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
//hide and show the pie chart
$(document).ready(function(){
$("#hide").click(function(){
$("#piechart").hide();
});
$("#show").click(function(){
$("#piechart").show();
});
});
</script>
</head>
<body>
<div class ="container-fluid">
<button id = "hide">hide the pie chart</button>
<button id = "show">show the pie chart</button>
<div id="piechart"></div>
</container>
</body>
<html>