กากบาท
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ภาพรวม
กากบาทคือเส้นแนวตั้งและแนวนอนบางๆ ที่มีจุดศูนย์กลางอยู่ที่จุดข้อมูลในแผนภูมิ เมื่อคุณในฐานะผู้สร้างแผนภูมิเปิดใช้กากบาทในแผนภูมิ ผู้ใช้จะสามารถกำหนดเป้าหมายองค์ประกอบเดียวได้ ดังนี้
เครื่องหมายกากบาทอาจปรากฏให้เห็นในโฟกัส การเลือก หรือทั้ง 2 อย่าง และใช้ได้กับแผนภูมิกระจาย แผนภูมิเส้น แผนภูมิพื้นที่ และส่วนเส้นและพื้นที่ของแผนภูมิผสม
ตัวอย่างง่ายๆ
วางเมาส์เหนือจุดด้านล่างหรือเลือกจุดเพื่อดูรูปกากบาท:
ต่อไปนี้คือหน้าเว็บที่สมบูรณ์ที่สร้างแผนภูมิข้างต้น โดยมีเส้นกากบาทเป็นตัวหนา
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load("current", {packages:["corechart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('number');
data.addColumn('number');
for (var i = 0; i < 100; i++)
data.addRow([Math.floor(Math.random()*100),
Math.floor(Math.random()*100)]);
var options = {
legend: 'none',
crosshair: { trigger: 'both' } // Display crosshairs on focus and selection.
};
var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
ตัวเลือกของ Crosshair
มีตัวเลือกกากบาทต่อไปนี้
crosshair: { trigger: 'both' } | แสดงทั้งในโฟกัสและรายการที่เลือก |
crosshair: { trigger: 'focus' } | แสดงผลเมื่อโฟกัสเท่านั้น |
crosshair: { trigger: 'selection' } | แสดงเมื่อเลือกเท่านั้น |
crosshair: { orientation: 'both' } | แสดงทั้งเส้นผมแนวตั้งและแนวนอน |
crosshair: { orientation: 'horizontal' } | แสดงเฉพาะเส้นผมแนวนอนเท่านั้น |
crosshair: { orientation: 'vertical' } | แสดงเฉพาะผมในแนวตั้ง |
crosshair: { color: color_string } | ตั้งค่าสีของเป้าหมาเป็น color_string เช่น 'red' หรือ '#f00' |
crosshair: { opacity: opacity_number } | ตั้งค่าความทึบแสงของเส้นไขว้เป็น opacity_number โดยที่ 0.0 แสดงความโปร่งใสเต็มที่และ 1.0 ทึบแสงเต็มที่ |
crosshair: { focused: { color: color_string } } | ตั้งค่าสีกากบาทเป็น color_string ในโฟกัส |
crosshair: { focused: { opacity: opacity_number } } | ตั้งค่าความทึบแสงของเส้นด้ายเป็น opacity_number ในโฟกัส |
crosshair: { selected: { color: color_string } } | ตั้งค่าสีกากบาทเป็น color_string ในการเลือก |
crosshair: { selected: { opacity: opacity_number } } | ตั้งค่าความทึบแสงของกากบาทเป็น opacity_number ในการเลือก |
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-07-10 UTC
[null,null,["อัปเดตล่าสุด 2024-07-10 UTC"],[],[],null,["# Crosshairs\n\n1. [Overview](#overview)\n2. [A Simple Example](#simple_example)\n3. [Crosshair Options](#options)\n\nOverview\n--------\n\nCrosshairs are thin vertical and horizontal lines centered on a\ndata point in a chart. When you, as a chart creator, enable crosshairs\nin your charts, your users will then be able to target a single\nelement:\n\nCrosshairs can appear on focus, selection, or both. They're\navailable for [scatter charts](/chart/interactive/docs/gallery/scatterchart),\n[line charts](/chart/interactive/docs/gallery/linechart), [area charts](/chart/interactive/docs/gallery/areachart),\nand for the line and area portions\nof [combo\ncharts](/chart/interactive/docs/gallery/combochart).\n\nA Simple Example\n----------------\n\nHover over the points below, or select them, to see crosshairs: \n\nHere's a complete web page that creates the above chart, with the\nline for crosshairs in bold: \n\n```\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:[\"corechart\"]});\n google.charts.setOnLoadCallback(drawChart);\n function drawChart() {\n var data = new google.visualization.DataTable();\n data.addColumn('number');\n data.addColumn('number');\n for (var i = 0; i \u003c 100; i++)\n data.addRow([Math.floor(Math.random()*100),\n Math.floor(Math.random()*100)]);\n var options = {\n legend: 'none',\n crosshair: { trigger: 'both' } // Display crosshairs on focus and selection.\n };\n var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));\n chart.draw(data, options);\n }\n \u003c/script\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003cdiv id=\"chart_div\" style=\"width: 900px; height: 500px;\"\u003e\u003c/div\u003e\n \u003c/body\u003e\n\u003c/html\u003e\n```\n\nCrosshair Options\n-----------------\n\nThe following crosshair options are available:\n\n|------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|\n| `crosshair: { trigger: 'both' }` | display on both focus and selection |\n| `crosshair: { trigger: 'focus' }` | display on focus only |\n| `crosshair: { trigger: 'selection' }` | display on selection only |\n| `crosshair: { orientation: 'both' }` | display both horizontal and vertical hairs |\n| `crosshair: { orientation: 'horizontal' }` | display horizontal hairs only |\n| `crosshair: { orientation: 'vertical' }` | display vertical hairs only |\n| `crosshair: { color: `*color_string*` }` | set crosshair color to *color_string* , e.g., `'red'` or `'#f00'` |\n| `crosshair: { opacity: `*opacity_number*` }` | set crosshair opacity to *opacity_number* , with `0.0` being fully transparent and `1.0` fully opaque |\n| `crosshair: { focused: { color: `*color_string*` } }` | set crosshair color to *color_string* on focus |\n| `crosshair: { focused: { opacity: `*opacity_number*` } }` | set crosshair opacity to *opacity_number* on focus |\n| `crosshair: { selected: { color: `*color_string*` } }` | set crosshair color to *color_string* on selection |\n| `crosshair: { selected: { opacity: `*opacity_number*` } }` | set crosshair opacity to *opacity_number* on selection |"]]