K 線圖
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
重要事項:Google 圖表工具的「圖片圖表」部分已自 2012 年 4 月 20 日起正式淘汰。但請放心,該功能將根據淘汰政策持續運作。
總覽
使用 Google Charts API 以圖片形式呈現的 K 線圖。
K 線圖的用途是顯示開盤價和收尾數值在總變異數上方重疊的部分。K 線圖經常用來呈現股票價值的行為。在這張圖表中,開盤價低於收盤價的項目會以綠色繪製,開盤價高於收盤價的項目則會以紅色顯示。詳情請參閱 Google Charts API 中的 K 線圖。
範例
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load("current", {packages:["imagechart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var options = {};
dataTable = google.visualization.arrayToDataTable([
['Gainers',10,30,45,60],
['Losers',20,35,25,45],
], true);
var chart = new google.visualization.ImageCandlestickChart(document.getElementById('chart_div'));
chart.draw(dataTable, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 400px; height: 240px;"></div>
</body>
</html>
載入中
google.charts.load
套件名稱為 "imagechart"
。
google.charts.load('current', {packages: [imagechart]});
視覺呈現的類別名稱為 google.visualization.ImageCandlestickChart
。
var visualization = new google.visualization.ImageCandlestickChart(container);
五個資料欄,其中每個資料列都代表一個 K 線標記:
- 第 0 欄:X 軸上做為標記標籤的字串。
- 第 1 個值:用於指定這個標記最低/最小值的數字。黑線的底邊。
- 第 2 欄:指定此標記開盤/初始值的數字。這是方塊的一條垂直邊線。如果低於「欄 3」的值,K 線會是綠色,否則為紅色。
- 第 3 欄:用於指定標記的收盤價/最終值的數字,這是方塊的另一條垂直邊線。如果低於「欄 2」的值,K 線會是紅色,否則為綠色。
- Col 4:指定這個標記最高值/最大值的數字。這就是黑線的頂部。
設定選項
除了一般圖片圖表支援的選項之外,K 線圖也支援下列選項:
名稱 |
類型 |
預設 |
說明 |
backgroundColor |
字串 |
「#FFFFFF」(白色) |
圖表的背景顏色。此為 #RRGGBB 字串,包括 # 符號。 |
showAxisLines |
boolean |
true |
是否顯示軸線。如果設為 False,系統就不會顯示軸標籤。 |
高度 |
號碼 |
所含元素的高度 |
圖表的高度,以像素為單位。如果 30 <高度或高度 > 1,000,這個值將預設為 200。 |
max |
號碼 |
資料最大值 |
Y 軸上限值。 |
分鐘 |
號碼 |
資料最小值 |
Y 軸最小值。 |
showCategoryLabels |
boolean |
true |
設為 false 時,隱藏 X 軸標籤。 |
showValueLabels |
boolean |
true |
如果是 false,則會隱藏 Y 軸標籤。 |
showValueLabelsInternal |
號碼 |
自動 |
Y 軸標籤之間的間距 (以像素為單位)。 |
title |
字串 |
'' |
顯示在圖表上方的文字。 |
寬度 |
號碼 |
所含元素的寬度 |
圖表的寬度,以像素為單位。如果寬度小於 30 或大於 1,000,則 width 會設為 300。 |
方法
方法 |
傳回類型 |
說明 |
draw(data, options) |
無 |
繪製圖表。 |
事件
您可以註冊聆聽一般圖片圖表頁面上所述的事件。
資料政策
請參閱圖表 API 記錄政策。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-07-10 (世界標準時間)。
[null,null,["上次更新時間:2024-07-10 (世界標準時間)。"],[],[],null,["# Candlestick Image Chart\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 candlestick chart that is rendered as an image using the [Google Charts API](/chart/image/docs/gallery/compound_charts#candlestick_charts).\n\nA candlestick chart is used to show an opening and closing value overlaid on top of a total variance. Candlestick charts are often used to show stock value behavior. In this chart, items where the opening value is less than the closing value are drawn in green, and items where the opening value is more than the closing value are drawn in red. See the [candlestick documentation in the Google Charts API](/chart/image/docs/gallery/compound_charts#candlestick_charts) for more information.\n\nExample\n-------\n\n\u003cbr /\u003e\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':\\['imagechart'\\]}); \\\u003c/script\\\u003e \\\u003cdiv id=\"chart_div\" style=\"width: 400px; height: 240px;\"\\\u003e\\\u003c/div\\\u003e google.charts.setOnLoadCallback(drawChart); function drawChart() { var options = {}; dataTable = google.visualization.arrayToDataTable(\\[ \\['Gainers',10,30,45,60\\], \\['Losers',20,35,25,45\\], \\], true); var chart = new google.visualization.ImageCandlestickChart(document.getElementById('chart_div')); chart.draw(dataTable, options); } \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:[\"imagechart\"]});\n google.charts.setOnLoadCallback(drawChart);\n\n function drawChart() {\n\n var options = {};\n dataTable = google.visualization.arrayToDataTable([\n ['Gainers',10,30,45,60],\n ['Losers',20,35,25,45],\n ], true);\n\n var chart = new google.visualization.ImageCandlestickChart(document.getElementById('chart_div'));\n chart.draw(dataTable, options);\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 `\"imagechart\"`. \n\n```transact-sql\n google.charts.load('current', {packages: [imagechart]});\n```\n\n\nThe visualization's class name is `google.visualization.`ImageCandlestickChart. \n\n```gdscript\n var visualization = new google.visualization.ImageCandlestickChart(container);\n```\n\nData Format\n-----------\n\nFive columns, where each row describes a single candlestick marker:\n\n- **Col 0:** String used as a label for this marker on the X axis.\n- **Col 1:** Number specifying the low/minimum value of this marker. This is the base of the black line.\n- **Col 2:** Number specifying the opening/initial value of this marker. This is one vertical border of the candle. If less than the column 3 value, the candle will be green; otherwise it will be red.\n- **Col 3:** Number specifying the closing/final value of this marker. This is the second vertical border of the candle. If less than the column 2 value, the candle will be red; otherwise it will be green.\n- **Col 4:** Number specifying the high/maximum value of this marker. This is the top of the black line.\n\nConfiguration Options\n---------------------\n\nIn addition to the options supported by the [Generic Image Chart](/chart/interactive/docs/gallery/genericimagechart#Configuration_Options),\nthe Candlestick Chart supports the following options:\n\n| Name | Type | Default | Description |\n|-------------------------|---------|----------------------------------|-------------------------------------------------------------------------------------------------------------------|\n| backgroundColor | string | '#FFFFFF' (white) | The background color for the chart. This is a #RRGGBB string, including the # mark. |\n| showAxisLines | boolean | true | Whether to show the axis lines. If set to false, then the axis labels will also not be shown. |\n| height | number | Height of the containing element | Height of the chart, in pixels. If 30 \\\u003c *height* or *height* \\\u003e 1,000 then this value will default to 200. |\n| max | number | Maximum data value | The maximum Y axis value. |\n| min | number | Minimum data value | The minimum Y axis value. |\n| showCategoryLabels | boolean | true | If false, hides the X axis labels. |\n| showValueLabels | boolean | true | If false, hides the Y axis labels. |\n| showValueLabelsInternal | number | auto | The spacing between the Y axis labels, in pixels. |\n| title | string | '' | Text to display above the chart. |\n| width | number | Width of the containing element | Width of the chart, in pixels. If *width* is less than 30 or greater than 1,000, then *width* will be set to 300. |\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)."]]