十字形
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
概览
十字准线是以图表中的数据点为中心的细竖线和水平线。如果您作为图表创建者,在图表中启用十字准线,您的用户便可定位单个元素:
十字准线可以出现在焦点和/或选定范围上。适用于散点图、折线图、面积图以及组合图表的折线图和面积图。
简单示例
将鼠标悬停在下方的点上或选择这些点,即可查看十字准线:
下面是一个用于创建上述图表的完整网页,其中十字线的线条以粗体显示:
<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: { 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 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-07-10。
[null,null,["最后更新时间 (UTC):2024-07-10。"],[],[],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 |"]]