การแสดงภาพ: แผนภูมิวงกลม (รูปภาพ)
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
สำคัญ: ส่วนแผนภูมิรูปภาพของเครื่องมือ Google แผนภูมิได้เลิกใช้งานอย่างเป็นทางการเมื่อวันที่ 20 เมษายน 2012 และจะยังใช้งานต่อตามนโยบายการเลิกใช้งาน
ภาพรวม
แผนภูมิวงกลมที่แสดงผลเป็นรูปภาพโดยใช้ 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);
2 คอลัมน์
คอลัมน์แรกควรเป็นสตริงและมีป้ายกำกับของสไลซ์
คอลัมน์ที่ 2 ควรเป็นตัวเลขและมีค่าของสไลซ์
ตัวเลือกการกำหนดค่า
คุณระบุตัวเลือกต่อไปนี้เป็นส่วนหนึ่งของออบเจ็กต์ตัวเลือกที่ส่งผ่านเมธอด draw()
ของการแสดงภาพได้
ชื่อ |
ประเภท |
ค่าเริ่มต้น |
คำอธิบาย |
backgroundColor |
string |
"#FFFFFF" (สีขาว) |
สีพื้นหลังของแผนภูมิในรูปแบบสี Chart API |
สี |
string |
อัตโนมัติ |
ระบุสีฐานที่จะใช้กับทุกชุด โดยแต่ละชุดจะเป็นการไล่ระดับสีตามสีที่ระบุ คุณระบุสีได้ในรูปแบบสีของ Chart API
ไม่สนใจหากระบุ colors ไว้ |
สี |
อาร์เรย์<สตริง> |
อัตโนมัติ |
ใช้เพื่อกำหนดสีที่เจาะจงให้กับชุดข้อมูลแต่ละชุด คุณระบุสีได้ในรูปแบบสีของ Chart API
สี i จะใช้กับคอลัมน์ข้อมูล i โดยล้อมรอบส่วนต้นตอ
หากมีคอลัมน์ข้อมูลมากกว่าสี หากชุดสีเดียวมีรูปแบบต่างๆ ที่ใช้ได้กับทุกชุด ให้ใช้ตัวเลือก color แทน |
enableEvents |
boolean |
false |
ทําให้แผนภูมิเกิดเหตุการณ์ที่ผู้ใช้ทริกเกอร์ เช่น คลิกหรือวางเมาส์เหนือ
รองรับเฉพาะแผนภูมิบางประเภท ดูเหตุการณ์ด้านล่าง |
ส่วนสูง |
ตัวเลข |
ความสูงของคอนเทนเนอร์ |
ความสูงของแผนภูมิเป็นพิกเซล |
เป็น 3 มิติ |
boolean |
false |
หากตั้งค่าเป็น "จริง" จะแสดงแผนภูมิ 3 มิติ |
ป้ายกำกับ |
string |
"none" |
ป้ายกำกับใด (หากมี) ที่จะแสดงสำหรับแต่ละชิ้นส่วน เลือกจากค่าต่อไปนี้
- "none" - ไม่มีป้ายกำกับ
- "value" - ใช้ค่าของส่วนแบ่งเป็นป้ายกำกับ
- "name" - ใช้ชื่อส่วนแบ่ง (ชื่อคอลัมน์)
|
คำอธิบาย |
string |
"ขวา" |
ตําแหน่งของคำอธิบายในแผนภูมิ โดยเลือกจากค่าใดค่าหนึ่งต่อไปนี้ "top", "bottom", "left", "right", "none" |
title |
string |
ไม่มีชื่อ |
ข้อความที่จะแสดงเหนือแผนภูมิ |
ความกว้าง |
ตัวเลข |
ความกว้างของคอนเทนเนอร์ |
ความกว้างของแผนภูมิเป็นพิกเซล |
วิธีการ
วิธีการ |
ประเภทการแสดงผล |
คำอธิบาย |
draw(data, options) |
ไม่มี |
วาดแผนภูมิ |
กิจกรรม
คุณลงทะเบียนเพื่อฟังเหตุการณ์ตามที่อธิบายไว้ในหน้าแผนภูมิรูปภาพทั่วไปได้
นโยบายข้อมูล
โปรดดูนโยบายการบันทึก Chart API
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-07-10 UTC
[null,null,["อัปเดตล่าสุด 2024-07-10 UTC"],[],[],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)."]]