How TO - Google Charts
เรียนรู้วิธีเพิ่ม Google Charts ในหน้าเว็บของคุณ
ตัวอย่าง
Google แผนภูมิวงกลม
เริ่มต้นด้วยหน้าเว็บพื้นฐานง่ายๆ
เพิ่ม <div> องค์ประกอบที่มี id "แผนภูมิวงกลม":
ตัวอย่าง
<!DOCTYPE html>
<html>
<body>
<h1>My Web Page</h1>
<div id="piechart"></div>
</body>
<html>
เพิ่มการอ้างอิงถึง Chart API ที่ google.com:
ตัวอย่าง
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
และเพิ่มฟังก์ชัน JavaScript:
ตัวอย่าง
<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',
2],
['Gym', 2],
['Sleep', 8]
]);
// Optional; add
a title and set the width and height of the chart
var options = {'title':'My
Average Day', 'width':550, 'height':400};
// Display the chart
inside the <div> element with id="piechart"
var chart = new
google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>