視覺化:圓餅圖 (圖片)
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
重要事項:Google 圖表工具的「圖片圖表」部分已自 2012 年 4 月 20 日起正式淘汰。但請放心,該功能將根據淘汰政策持續運作。
總覽
使用 Google Charts API 顯示為圖片的圓餅圖。
範例
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load("current", {packages:["imagepiechart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]);
var chart = new google.visualization.ImagePieChart(document.getElementById('chart_div'));
chart.draw(data, {width: 430, height: 240, title: 'My Daily Activities'});
}
</script>
</head>
<body>
<div id="chart_div" style="width: 400px; height: 240px;"></div>
</body>
</html>
載入中
google.charts.load
套件名稱為 "imagepiechart"
:
google.charts.load('current', {packages: ['imagepiechart']});
視覺呈現的類別名稱為 google.visualization.ImagePieChart
var visualization = new google.visualization.ImagePieChart(container);
兩欄。
第一欄應為字串且包含切片標籤。
第二欄應為數字且包含片段值。
設定選項
您可以在 options 物件中指定下列選項,該物件會傳遞至視覺化的 draw()
方法。
名稱 |
類型 |
預設 |
說明 |
backgroundColor |
字串 |
「#FFFFFF」(白色) |
圖表 API 顏色格式的圖表背景顏色。 |
顏色 |
字串 |
自動 |
指定所有序列要使用的基本顏色;每個系列都會是指定顏色的階梯。您可以使用圖表 API 顏色格式指定顏色,如果指定 colors ,系統會忽略這項設定。 |
顏色 |
陣列<字串> |
自動 |
藉此為各個資料序列指定特定顏色。您可以使用圖表 API 顏色格式指定顏色。顏色 i 會用於資料欄 i,如果資料欄超過顏色,則會從頭到頭換行。如果所有系列都接受單一顏色的變化版本,請改用 color 選項。 |
enableEvents |
boolean |
false |
讓圖表擲回使用者觸發的事件,例如點擊或滑鼠遊標懸停。僅支援特定圖表類型。請參閱下方的「事件」一節。 |
高度 |
號碼 |
容器高度 |
圖表的高度 (以像素為單位)。 |
是 3D |
boolean |
false |
如果設為 True,則會顯示 3D 圖表。 |
標籤 |
字串 |
「無」 |
每個片段顯示的標籤 (如有)。請選擇下列值:
- 「無」- 無標籤。
- 「值」- 使用片段值做為標籤。
- 「name」:使用切片名稱 (欄名稱)。
|
傳說 |
字串 |
「右」 |
圖表中圖例的位置。請選擇下列其中一個值:「top」、「bottom」、「left」、「right」或「none」。 |
title |
字串 |
無標題 |
顯示在圖表上方的文字。 |
寬度 |
號碼 |
容器寬度 |
圖表的寬度 (以像素為單位)。 |
方法
方法 |
傳回類型 |
說明 |
draw(data, options) |
無 |
繪製圖表。 |
事件
您可以註冊聆聽一般圖片圖表網頁中所述的事件。
資料政策
請參閱「圖表 API 記錄政策」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-07-10 (世界標準時間)。
[null,null,["上次更新時間:2024-07-10 (世界標準時間)。"],[],[],null,["# Visualization: Pie Chart (Image)\n\n**Important:** The Image Charts portion of Google Chart Tools has been [officially deprecated](http://googledevelopers.blogspot.com/2012/04/changes-to-deprecation-policies-and-api.html) as of April 20, 2012. It will continue to work as per our [deprecation policy](/chart/terms). \n1. [Overview](#Overview)\n2. [Example](#Example)\n3. [Loading](#Loading)\n4. [Data Format](#Data_Format)\n5. [Configuration Options](#Configuration_Options)\n6. [Methods](#Methods)\n7. [Events](#Events)\n8. [Data Policy](#Data_Policy)\n\nOverview\n--------\n\n\nA pie chart that is rendered as an image using the [Google Charts API](/chart/image/docs/gallery/pie_charts).\n\nExample\n-------\n\n\\\u003cscript type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"\\\u003e\\\u003c/script\\\u003e \\\u003cscript type=\"text/javascript\"\\\u003e google.charts.load('current', {'packages':\\['imagepiechart'\\]}); \\\u003c/script\\\u003e \\\u003cdiv id=\"chart_div\" style=\"width: 400px; height: 240px;\"\\\u003e\\\u003c/div\\\u003e google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable(\\[ \\['Task', 'Hours per Day'\\], \\['Work', 11\\], \\['Eat', 2\\], \\['Commute', 2\\], \\['Watch TV', 2\\], \\['Sleep', 7\\] \\]); var chart = new google.visualization.ImagePieChart(document.getElementById('chart_div')); chart.draw(data, {width: 430, height: 240, title: 'My Daily Activities'}); } \n\n```html\n\u003chtml\u003e\n \u003chead\u003e\n \u003cscript type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"\u003e\u003c/script\u003e\n \u003cscript type=\"text/javascript\"\u003e\n google.charts.load(\"current\", {packages:[\"imagepiechart\"]});\n google.charts.setOnLoadCallback(drawChart);\n\n function drawChart() {\n var data = google.visualization.arrayToDataTable([\n ['Task', 'Hours per Day'],\n ['Work', 11],\n ['Eat', 2],\n ['Commute', 2],\n ['Watch TV', 2],\n ['Sleep', 7]\n ]);\n\n var chart = new google.visualization.ImagePieChart(document.getElementById('chart_div'));\n\n chart.draw(data, {width: 430, height: 240, title: 'My Daily Activities'});\n }\n \u003c/script\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003cdiv id=\"chart_div\" style=\"width: 400px; height: 240px;\"\u003e\u003c/div\u003e\n \u003c/body\u003e\n\u003c/html\u003e\n```\n\nLoading\n-------\n\n\nThe `google.charts.load` package name is `\"imagepiechart\"`: \n\n```gdscript\n google.charts.load('current', {packages: ['imagepiechart']});\n```\n\n\nThe visualization's class name is `google.visualization.ImagePieChart` \n\n```gdscript\n var visualization = new google.visualization.ImagePieChart(container);\n```\n\nData Format\n-----------\n\n\nTwo columns.\nThe first column should be a string, and contain the slice label.\nThe second column should be a number, and contain the slice value.\n\nConfiguration Options\n---------------------\n\nYou can specify the following options as part of the *options* object passed into\nthe visualization's `draw()` method.\n\n| Name | Type | Default | Description |\n|-----------------|-----------------|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| backgroundColor | string | '#FFFFFF' (white) | The background color for the chart in the [Chart API color format](/chart/image/docs/chart_params#gcharts_rgb). |\n| color | string | Auto | Specifies a base color to use for all series; each series will be a gradation of the color specified. Colors are specified in the [Chart API color format](/chart/image/docs/chart_params#gcharts_rgb). Ignored if `colors` is specified. |\n| colors | Array\\\u003cstring\\\u003e | Auto | Use this to assign specific colors to each data series. Colors are specified in the [Chart API color format](/chart/image/docs/chart_params#gcharts_rgb). Color i is used for data column i, wrapping around to the beginning if there are more data columns than colors. If variations of a single color is acceptable for all series, use the `color` option instead. |\n| enableEvents | boolean | false | Causes charts to throw user-triggered events such as click or mouse over. Supported only for specific chart types. See [Events](#Events) below. |\n| height | number | Container's height | Height of the chart in pixels. |\n| is3D | boolean | false | If set to true, displays a three-dimensional chart. |\n| labels | string | 'none' | What label, if any, to show for each slice. Choose from the following values: - 'none' - No labels. - 'value' - Use the slice value as a label. - 'name' - Use the slice name (the column name). |\n| legend | string | 'right' | The location of the legend on the chart. Choose from one of the following values: 'top', 'bottom', 'left', 'right', 'none'. |\n| title | string | no title | Text to display above the chart. |\n| width | number | Container's width | Width of the chart in pixels. |\n\nMethods\n-------\n\n| Method | Return Type | Description |\n|-----------------------|-------------|------------------|\n| `draw(data, options)` | none | Draws the chart. |\n\nEvents\n------\n\nYou can register to hear the events described on the [Generic\nImage Chart](/chart/interactive/docs/gallery/genericimagechart#Events) page.\n\nData Policy\n-----------\n\n\nPlease refer to the [Chart API logging policy](/chart/interactive/faq#logging)."]]