modes.html 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  1. <!DOCTYPE HTML>
  2. <html lang="" >
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  6. <title>Modes · Chart.js documentation</title>
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  8. <meta name="description" content="">
  9. <meta name="generator" content="GitBook 3.2.2">
  10. <meta name="author" content="chartjs">
  11. <link rel="stylesheet" href="../../gitbook/style.css">
  12. <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-plus/search.css">
  13. <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
  14. <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
  15. <link rel="stylesheet" href="../../style.css">
  16. <meta name="HandheldFriendly" content="true"/>
  17. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  18. <meta name="apple-mobile-web-app-capable" content="yes">
  19. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  20. <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
  21. <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
  22. <link rel="next" href="../options.html" />
  23. <link rel="prev" href="events.html" />
  24. <link rel="stylesheet" href="../../gitbook/gitbook-plugin-chartjs/style.css">
  25. <script src="../../gitbook/gitbook-plugin-chartjs/Chart.bundle.js"></script>
  26. <script src="../../gitbook/gitbook-plugin-chartjs/chartjs-plugin-deferred.js"></script>
  27. </head>
  28. <body>
  29. <div class="book">
  30. <div class="book-summary">
  31. <div id="book-search-input" role="search">
  32. <input type="text" placeholder="Type to search" />
  33. </div>
  34. <nav role="navigation">
  35. <ul class="summary">
  36. <li class="chapter " data-level="1.1" data-path="../../">
  37. <a href="../../">
  38. Chart.js
  39. </a>
  40. </li>
  41. <li class="chapter " data-level="1.2" data-path="../../getting-started/">
  42. <a href="../../getting-started/">
  43. Getting Started
  44. </a>
  45. <ul class="articles">
  46. <li class="chapter " data-level="1.2.1" data-path="../../getting-started/installation.html">
  47. <a href="../../getting-started/installation.html">
  48. Installation
  49. </a>
  50. </li>
  51. <li class="chapter " data-level="1.2.2" data-path="../../getting-started/integration.html">
  52. <a href="../../getting-started/integration.html">
  53. Integration
  54. </a>
  55. </li>
  56. <li class="chapter " data-level="1.2.3" data-path="../../getting-started/usage.html">
  57. <a href="../../getting-started/usage.html">
  58. Usage
  59. </a>
  60. </li>
  61. </ul>
  62. </li>
  63. <li class="chapter " data-level="1.3" data-path="../">
  64. <a href="../">
  65. General
  66. </a>
  67. <ul class="articles">
  68. <li class="chapter " data-level="1.3.1" data-path="../responsive.html">
  69. <a href="../responsive.html">
  70. Responsive
  71. </a>
  72. </li>
  73. <li class="chapter " data-level="1.3.2" data-path="../device-pixel-ratio.html">
  74. <a href="../device-pixel-ratio.html">
  75. Pixel Ratio
  76. </a>
  77. </li>
  78. <li class="chapter " data-level="1.3.3" data-path="./">
  79. <a href="./">
  80. Interactions
  81. </a>
  82. <ul class="articles">
  83. <li class="chapter " data-level="1.3.3.1" data-path="events.html">
  84. <a href="events.html">
  85. Events
  86. </a>
  87. </li>
  88. <li class="chapter active" data-level="1.3.3.2" data-path="modes.html">
  89. <a href="modes.html">
  90. Modes
  91. </a>
  92. </li>
  93. </ul>
  94. </li>
  95. <li class="chapter " data-level="1.3.4" data-path="../options.html">
  96. <a href="../options.html">
  97. Options
  98. </a>
  99. </li>
  100. <li class="chapter " data-level="1.3.5" data-path="../colors.html">
  101. <a href="../colors.html">
  102. Colors
  103. </a>
  104. </li>
  105. <li class="chapter " data-level="1.3.6" data-path="../fonts.html">
  106. <a href="../fonts.html">
  107. Fonts
  108. </a>
  109. </li>
  110. </ul>
  111. </li>
  112. <li class="chapter " data-level="1.4" data-path="../../configuration/">
  113. <a href="../../configuration/">
  114. Configuration
  115. </a>
  116. <ul class="articles">
  117. <li class="chapter " data-level="1.4.1" data-path="../../configuration/animations.html">
  118. <a href="../../configuration/animations.html">
  119. Animations
  120. </a>
  121. </li>
  122. <li class="chapter " data-level="1.4.2" data-path="../../configuration/layout.html">
  123. <a href="../../configuration/layout.html">
  124. Layout
  125. </a>
  126. </li>
  127. <li class="chapter " data-level="1.4.3" data-path="../../configuration/legend.html">
  128. <a href="../../configuration/legend.html">
  129. Legend
  130. </a>
  131. </li>
  132. <li class="chapter " data-level="1.4.4" data-path="../../configuration/title.html">
  133. <a href="../../configuration/title.html">
  134. Title
  135. </a>
  136. </li>
  137. <li class="chapter " data-level="1.4.5" data-path="../../configuration/tooltip.html">
  138. <a href="../../configuration/tooltip.html">
  139. Tooltip
  140. </a>
  141. </li>
  142. <li class="chapter " data-level="1.4.6" data-path="../../configuration/elements.html">
  143. <a href="../../configuration/elements.html">
  144. Elements
  145. </a>
  146. </li>
  147. </ul>
  148. </li>
  149. <li class="chapter " data-level="1.5" data-path="../../charts/">
  150. <a href="../../charts/">
  151. Charts
  152. </a>
  153. <ul class="articles">
  154. <li class="chapter " data-level="1.5.1" data-path="../../charts/line.html">
  155. <a href="../../charts/line.html">
  156. Line
  157. </a>
  158. </li>
  159. <li class="chapter " data-level="1.5.2" data-path="../../charts/bar.html">
  160. <a href="../../charts/bar.html">
  161. Bar
  162. </a>
  163. </li>
  164. <li class="chapter " data-level="1.5.3" data-path="../../charts/radar.html">
  165. <a href="../../charts/radar.html">
  166. Radar
  167. </a>
  168. </li>
  169. <li class="chapter " data-level="1.5.4" data-path="../../charts/doughnut.html">
  170. <a href="../../charts/doughnut.html">
  171. Doughnut & Pie
  172. </a>
  173. </li>
  174. <li class="chapter " data-level="1.5.5" data-path="../../charts/polar.html">
  175. <a href="../../charts/polar.html">
  176. Polar Area
  177. </a>
  178. </li>
  179. <li class="chapter " data-level="1.5.6" data-path="../../charts/bubble.html">
  180. <a href="../../charts/bubble.html">
  181. Bubble
  182. </a>
  183. </li>
  184. <li class="chapter " data-level="1.5.7" data-path="../../charts/scatter.html">
  185. <a href="../../charts/scatter.html">
  186. Scatter
  187. </a>
  188. </li>
  189. <li class="chapter " data-level="1.5.8" data-path="../../charts/area.html">
  190. <a href="../../charts/area.html">
  191. Area
  192. </a>
  193. </li>
  194. <li class="chapter " data-level="1.5.9" data-path="../../charts/mixed.html">
  195. <a href="../../charts/mixed.html">
  196. Mixed
  197. </a>
  198. </li>
  199. </ul>
  200. </li>
  201. <li class="chapter " data-level="1.6" data-path="../../axes/">
  202. <a href="../../axes/">
  203. Axes
  204. </a>
  205. <ul class="articles">
  206. <li class="chapter " data-level="1.6.1" data-path="../../axes/cartesian/">
  207. <a href="../../axes/cartesian/">
  208. Cartesian
  209. </a>
  210. <ul class="articles">
  211. <li class="chapter " data-level="1.6.1.1" data-path="../../axes/cartesian/category.html">
  212. <a href="../../axes/cartesian/category.html">
  213. Category
  214. </a>
  215. </li>
  216. <li class="chapter " data-level="1.6.1.2" data-path="../../axes/cartesian/linear.html">
  217. <a href="../../axes/cartesian/linear.html">
  218. Linear
  219. </a>
  220. </li>
  221. <li class="chapter " data-level="1.6.1.3" data-path="../../axes/cartesian/logarithmic.html">
  222. <a href="../../axes/cartesian/logarithmic.html">
  223. Logarithmic
  224. </a>
  225. </li>
  226. <li class="chapter " data-level="1.6.1.4" data-path="../../axes/cartesian/time.html">
  227. <a href="../../axes/cartesian/time.html">
  228. Time
  229. </a>
  230. </li>
  231. </ul>
  232. </li>
  233. <li class="chapter " data-level="1.6.2" data-path="../../axes/radial/">
  234. <a href="../../axes/radial/">
  235. Radial
  236. </a>
  237. <ul class="articles">
  238. <li class="chapter " data-level="1.6.2.1" data-path="../../axes/radial/linear.html">
  239. <a href="../../axes/radial/linear.html">
  240. Linear
  241. </a>
  242. </li>
  243. </ul>
  244. </li>
  245. <li class="chapter " data-level="1.6.3" data-path="../../axes/labelling.html">
  246. <a href="../../axes/labelling.html">
  247. Labelling
  248. </a>
  249. </li>
  250. <li class="chapter " data-level="1.6.4" data-path="../../axes/styling.html">
  251. <a href="../../axes/styling.html">
  252. Styling
  253. </a>
  254. </li>
  255. </ul>
  256. </li>
  257. <li class="chapter " data-level="1.7" data-path="../../developers/">
  258. <a href="../../developers/">
  259. Developers
  260. </a>
  261. <ul class="articles">
  262. <li class="chapter " data-level="1.7.1" data-path="../../developers/api.html">
  263. <a href="../../developers/api.html">
  264. Chart.js API
  265. </a>
  266. </li>
  267. <li class="chapter " data-level="1.7.2" data-path="../../developers/updates.html">
  268. <a href="../../developers/updates.html">
  269. Updating Charts
  270. </a>
  271. </li>
  272. <li class="chapter " data-level="1.7.3" data-path="../../developers/plugins.html">
  273. <a href="../../developers/plugins.html">
  274. Plugins
  275. </a>
  276. </li>
  277. <li class="chapter " data-level="1.7.4" data-path="../../developers/charts.html">
  278. <a href="../../developers/charts.html">
  279. New Charts
  280. </a>
  281. </li>
  282. <li class="chapter " data-level="1.7.5" data-path="../../developers/axes.html">
  283. <a href="../../developers/axes.html">
  284. New Axes
  285. </a>
  286. </li>
  287. <li class="chapter " data-level="1.7.6" data-path="../../developers/contributing.html">
  288. <a href="../../developers/contributing.html">
  289. Contributing
  290. </a>
  291. </li>
  292. </ul>
  293. </li>
  294. <li class="chapter " data-level="1.8" data-path="../../notes/">
  295. <a href="../../notes/">
  296. Additional Notes
  297. </a>
  298. <ul class="articles">
  299. <li class="chapter " data-level="1.8.1" data-path="../../notes/comparison.html">
  300. <a href="../../notes/comparison.html">
  301. Comparison Table
  302. </a>
  303. </li>
  304. <li class="chapter " data-level="1.8.2" data-path="../../notes/extensions.html">
  305. <a href="../../notes/extensions.html">
  306. Popular Extensions
  307. </a>
  308. </li>
  309. <li class="chapter " data-level="1.8.3" data-path="../../notes/license.html">
  310. <a href="../../notes/license.html">
  311. License
  312. </a>
  313. </li>
  314. </ul>
  315. </li>
  316. <li class="divider"></li>
  317. <li>
  318. <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
  319. Published with GitBook
  320. </a>
  321. </li>
  322. </ul>
  323. </nav>
  324. </div>
  325. <div class="book-body">
  326. <div class="body-inner">
  327. <div class="book-header" role="navigation">
  328. <!-- Title -->
  329. <h1>
  330. <i class="fa fa-circle-o-notch fa-spin"></i>
  331. <a href="../.." >Modes</a>
  332. </h1>
  333. </div>
  334. <div class="page-wrapper" tabindex="-1" role="main">
  335. <div class="page-inner">
  336. <div class="search-plus" id="book-search-results">
  337. <div class="search-noresults">
  338. <section class="normal markdown-section">
  339. <h1 id="interaction-modes">Interaction Modes</h1>
  340. <p>When configuring interaction with the graph via hover or tooltips, a number of different modes are available.</p>
  341. <p>The modes are detailed below and how they behave in conjunction with the <code>intersect</code> setting.</p>
  342. <h2 id="point">point</h2>
  343. <p>Finds all of the items that intersect the point.</p>
  344. <pre><code class="lang-javascript"><span class="hljs-keyword">var</span> chart = <span class="hljs-keyword">new</span> Chart(ctx, {
  345. type: <span class="hljs-string">&apos;line&apos;</span>,
  346. data: data,
  347. options: {
  348. tooltips: {
  349. mode: <span class="hljs-string">&apos;point&apos;</span>
  350. }
  351. }
  352. })
  353. </code></pre>
  354. <h2 id="nearest">nearest</h2>
  355. <p>Gets the item that is nearest to the point. The nearest item is determined based on the distance to the center of the chart item (point, bar). If 2 or more items are at the same distance, the one with the smallest area is used. If <code>intersect</code> is true, this is only triggered when the mouse position intersects an item in the graph. This is very useful for combo charts where points are hidden behind bars.</p>
  356. <pre><code class="lang-javascript"><span class="hljs-keyword">var</span> chart = <span class="hljs-keyword">new</span> Chart(ctx, {
  357. type: <span class="hljs-string">&apos;line&apos;</span>,
  358. data: data,
  359. options: {
  360. tooltips: {
  361. mode: <span class="hljs-string">&apos;nearest&apos;</span>
  362. }
  363. }
  364. })
  365. </code></pre>
  366. <h2 id="single-deprecated">single (deprecated)</h2>
  367. <p>Finds the first item that intersects the point and returns it. Behaves like &apos;nearest&apos; mode with intersect = true.</p>
  368. <h2 id="label-deprecated">label (deprecated)</h2>
  369. <p>See <code>&apos;index&apos;</code> mode</p>
  370. <h2 id="index">index</h2>
  371. <p>Finds item at the same index. If the <code>intersect</code> setting is true, the first intersecting item is used to determine the index in the data. If <code>intersect</code> false the nearest item, in the x direction, is used to determine the index.</p>
  372. <pre><code class="lang-javascript"><span class="hljs-keyword">var</span> chart = <span class="hljs-keyword">new</span> Chart(ctx, {
  373. type: <span class="hljs-string">&apos;line&apos;</span>,
  374. data: data,
  375. options: {
  376. tooltips: {
  377. mode: <span class="hljs-string">&apos;index&apos;</span>
  378. }
  379. }
  380. })
  381. </code></pre>
  382. <p>To use index mode in a chart like the horizontal bar chart, where we search along the y direction, you can use the <code>axis</code> setting introduced in v2.7.0. By setting this value to <code>&apos;y&apos;</code> on the y direction is used.</p>
  383. <pre><code class="lang-javascript"><span class="hljs-keyword">var</span> chart = <span class="hljs-keyword">new</span> Chart(ctx, {
  384. type: <span class="hljs-string">&apos;horizontalBar&apos;</span>,
  385. data: data,
  386. options: {
  387. tooltips: {
  388. mode: <span class="hljs-string">&apos;index&apos;</span>,
  389. axis: <span class="hljs-string">&apos;y&apos;</span>
  390. }
  391. }
  392. })
  393. </code></pre>
  394. <h2 id="x-axis-deprecated">x-axis (deprecated)</h2>
  395. <p>Behaves like <code>&apos;index&apos;</code> mode with <code>intersect = false</code>.</p>
  396. <h2 id="dataset">dataset</h2>
  397. <p>Finds items in the same dataset. If the <code>intersect</code> setting is true, the first intersecting item is used to determine the index in the data. If <code>intersect</code> false the nearest item is used to determine the index.</p>
  398. <pre><code class="lang-javascript"><span class="hljs-keyword">var</span> chart = <span class="hljs-keyword">new</span> Chart(ctx, {
  399. type: <span class="hljs-string">&apos;line&apos;</span>,
  400. data: data,
  401. options: {
  402. tooltips: {
  403. mode: <span class="hljs-string">&apos;dataset&apos;</span>
  404. }
  405. }
  406. })
  407. </code></pre>
  408. <h2 id="x">x</h2>
  409. <p>Returns all items that would intersect based on the <code>X</code> coordinate of the position only. Would be useful for a vertical cursor implementation. Note that this only applies to cartesian charts</p>
  410. <pre><code class="lang-javascript"><span class="hljs-keyword">var</span> chart = <span class="hljs-keyword">new</span> Chart(ctx, {
  411. type: <span class="hljs-string">&apos;line&apos;</span>,
  412. data: data,
  413. options: {
  414. tooltips: {
  415. mode: <span class="hljs-string">&apos;x&apos;</span>
  416. }
  417. }
  418. })
  419. </code></pre>
  420. <h2 id="y">y</h2>
  421. <p>Returns all items that would intersect based on the <code>Y</code> coordinate of the position. This would be useful for a horizontal cursor implementation. Note that this only applies to cartesian charts.</p>
  422. <pre><code class="lang-javascript"><span class="hljs-keyword">var</span> chart = <span class="hljs-keyword">new</span> Chart(ctx, {
  423. type: <span class="hljs-string">&apos;line&apos;</span>,
  424. data: data,
  425. options: {
  426. tooltips: {
  427. mode: <span class="hljs-string">&apos;y&apos;</span>
  428. }
  429. }
  430. })
  431. </code></pre>
  432. </section>
  433. </div>
  434. <div class="search-results">
  435. <div class="has-results">
  436. <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
  437. <ul class="search-results-list"></ul>
  438. </div>
  439. <div class="no-results">
  440. <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
  441. </div>
  442. </div>
  443. </div>
  444. </div>
  445. </div>
  446. </div>
  447. <a href="events.html" class="navigation navigation-prev " aria-label="Previous page: Events">
  448. <i class="fa fa-angle-left"></i>
  449. </a>
  450. <a href="../options.html" class="navigation navigation-next " aria-label="Next page: Options">
  451. <i class="fa fa-angle-right"></i>
  452. </a>
  453. </div>
  454. <script>
  455. var gitbook = gitbook || [];
  456. gitbook.push(function() {
  457. gitbook.page.hasChanged({"page":{"title":"Modes","level":"1.3.3.2","depth":3,"next":{"title":"Options","level":"1.3.4","depth":2,"path":"general/options.md","ref":"general/options.md","articles":[]},"previous":{"title":"Events","level":"1.3.3.1","depth":3,"path":"general/interactions/events.md","ref":"general/interactions/events.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","search-plus","anchorjs","chartjs","ga"],"root":"./docs","styles":{"website":"style.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"anchorjs":{"icon":"#","placement":"left","visible":"always"},"ga":{"configuration":"auto","token":"UA-28909194-3"},"theme-default":{"styles":{"website":"style.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"search-plus":{},"chartjs":{"defaults":null},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}},"theme":"default","author":"chartjs","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Chart.js documentation","gitbook":"3.2.2"},"file":{"path":"general/interactions/modes.md","mtime":"2018-03-01T21:46:31.679Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2018-03-01T21:50:47.970Z"},"basePath":"../..","book":{"language":""}});
  458. });
  459. </script>
  460. </div>
  461. <script src="../../gitbook/gitbook.js"></script>
  462. <script src="../../gitbook/theme.js"></script>
  463. <script src="../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
  464. <script src="../../gitbook/gitbook-plugin-search-plus/search.js"></script>
  465. <script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/4.1.0/anchor.min.js"></script>
  466. <script src="../../gitbook/gitbook-plugin-anchorjs/anchor-style.js"></script>
  467. <script src="../../gitbook/gitbook-plugin-ga/plugin.js"></script>
  468. <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
  469. <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
  470. </body>
  471. </html>