Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

什么是 Google Charts?


HTML

Google Maps 是一个 Google API

Google Fonts 是一个 Google API

Google Charts 是一个 Google API


学习如何将 Google Charts 添加到你的网页中。



Google 饼图

从一个简单的基本网页开始。

添加一个带有 id 为 "piechart" 的 <div> 元素

示例

<!DOCTYPE html>
<html>
<body>

<h1>我的网页</h1>

<div id="piechart"></div>

</body>
<html>


在 google.com 添加对 Chart API 的引用

示例

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

并添加一个 JavaScript 函数

示例

<script type="text/javascript">
// 加载 google 图表
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);

// 绘制图表并设置图表值
function drawChart() {
  var data = google.visualization.arrayToDataTable([
  ['任务', '每天小时数'],
  ['工作', 8],
  ['朋友', 2],
  ['吃饭', 2],
  ['看电视', 2],
  ['健身', 2],
  ['睡觉', 8]
]);

  // 可选;添加标题并设置图表的宽度和高度
  var options = {'title':'我的平均一天', 'width':550, 'height':400};

  // 在 id 为 "piechart" 的 <div> 元素内显示图表
  var chart = new google.visualization.PieChart(document.getElementById('piechart'));
  chart.draw(data, options);
}
</script>
自己尝试 »

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.