Issue with ChartJs version 2.8.0: The custom tooltip remains visible even when clicking outside the chart canvas or moving the mouse pointer

I am utilizing ChartJs to display a line chart with a custom tooltip that appears upon the click event of the data points.

The challenge I am facing is that the custom tooltip remains visible even when the mouse pointer is outside the chart canvas area.

To address this issue and ensure the tooltip is only displayed upon clicking the points, I have configured the chart options to respond solely to click events like so:

options: {
  events: ['click'],
.....
..

Kindly confirm if the above approach is correct for showing tooltips exclusively on click events and not other types of events.

As a result of this setup, neither the default Chart.js tooltip nor the custom tooltip automatically hides when the mouse is moved or clicked outside the chart canvas area.

If anyone could assist me in finding a solution to this issue, it would be greatly appreciated.

Here is the link to my JS Fiddle Example

Below is the complete code:

JS:

// JavaScript code here...

HTML:

<body>
    <canvas id="chartJSContainer" width="600" height="400"></canvas>
</body>

CSS:

// CSS code here...

Answer №1

Hooray! The answer has been found! Simply by incorporating the mouseout event into the chart's events option, the issue was successfully resolved.

Now, the custom tooltip that was added will disappear when the mouse is moved or clicked outside of the chart area.

Code:

options: {
  events: ["click", "mouseout"],
....
...

For reference, here is the link to my updated JS Fiddel example.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

In Firefox, the CSS height and width values are displayed as X pixels, whereas in Internet Explorer, they are automatically set to 'auto'

When it comes to measuring div box dimensions, jQuery can be a handy tool. Here is an example code snippet: $(document).ready(function(){ var h = $("#testbox").css("height"); }); Interestingly, the same code can give different results in different brow ...

How can I showcase the index of `<tr>` and `<td>` elements in a dynamically generated table

How can I print the index of table rows and data on click in javascript? <html> <head> <title>Table Creation</title> <script language="javascript" type="text/javascript"> function createTable() { ...

Determining the character encoding of a JavaScript source code file

For my German users, I want to display a status message with umlauts (ä/ü/ö) directly in the source file instead of requiring an extra download for messages. However, I'm having trouble defining the encoding for a JS source file. Is there a way si ...

Unusual Behavior of JavaScript for..in and enum

I'm facing an issue with the peculiar behavior of the for..in loop in JavaScript. Here's the structure of my HTML: <div id="quarter_circle_top_left">...</div> <div id="quarter_circle_top_right">...</div> <div id="quart ...

Sending data between Node.js middleware components

if (token_count == 1) { var user_name = rows[0].user_name; next(); } else { data = { message: "Invalid Token" } res.send(data); } I must pass the parameter user_name to function next(). When next() is called, it triggers the fo ...

Utilize a custom function on dynamically generated elements

I am utilizing the following jQuery function: $("#agenda_image_1,#agenda_image_2,#agenda_image_3").PictureCut({ InputOfImageDirectory : "image", PluginFolderOnServer : "../xxx/modules/xxx/assets/js/jQuery-Picture-Cut-master/", Fol ...

Unable to Scroll HTML Division

At the moment, I am working on a new website. I have a div where I place images and overlay text on them to describe the images. The issue I am facing is that the text does not scroll even though the scroll bar is visible. This is my HTML: <!DOCTY ...

Utilizing Next.js with formidable for efficient parsing of multipart/form-data

I've been working on developing a next.js application that is supposed to handle multipart/form-data and then process it to extract the name, address, and file data from an endpoint. Although I attempted to use Formidable library for parsing the form ...

Changing the background color using jQuery switch case statement

I am attempting to utilize jquery to dynamically change the background image of a webpage based on different cases in a JavaScript switch statement. I have completed three steps: 1) Included this script tag in my HTML document: <script src="http://co ...

Is there a way to automatically populate the result input field with the dynamic calculation results from a dynamic calculator in Angular6?

My current challenge involves creating dynamic calculators with customizable fields. For example, I can generate a "Percentage Calculator" with specific input fields or a "Compound Interest" Calculator with different input requirements and formulas. Succes ...

Display all months on mobile screen using Mui DesktopDatePicker

Looking for a Better Date Range Picker I've been working on a project that requires a date range picker, and I opted to use the Mui date range picker. While it works well on desktop, I encountered an issue with mobile view where only one month is sho ...

Can we display an express view in response to a WebSocket event?

My goal is to display an express view within a websocket event as shown below: socket.on('name', function () { //prompt the client to render a specific express view }); ...

Analyzing latency in node.js through numerous requests

Is there a way to send multiple requests in a loop, and measure the time of each request? In PHP I'd do: require 'vendor/autoload.php'; use GuzzleHttp\Client; $client = new Client(); for ($i = 0; $i < 100; $i++) { $start = mic ...

My pure JS component is not being recognized by ASP.NET Core when integrated with Vue.js

I decided to try writing a simple component in "ASP.NET Core with Vue.js" template using pure JS instead of Typescript. However, I encountered an issue where my port does not seem to work properly. What could be causing this problem? in ./ClientApp/compon ...

Navigate to the location using AngularJS elements in the JavaScript iframe1

Dealing with an issue while working on AngularJS. I am facing a frustrating problem where I am attempting to use one link to open links in two separate iframes. All aspects of this function correctly, except for the actual links. The issue arises when usin ...

Struggling with the alignment of pictures inside a container

I utilized the Instafeed.js library to fetch the three most recent images from an Instagram account. These images are loaded into a specific div and I successfully customized their styling according to my requirements. However, the current setup is quite s ...

Store the output of the function in a variable

Here is a script that was provided to me: <div id="container1"> <script> var script = document.createElement("script"); script.type = "text/javascript"; script.text = 'document.write(xmlDoc.getElementsByTagName("INFO") ...

Unable to group the array based on the key value using Jquery or Javascript

I am looking to group my array values based on specific key values using Jquery/Javascript, but I am facing issues with my current code. Let me explain the code below. var dataArr=[ { "login_id":"9937229853", "alloc ...

Refresh Ajax/Javascripts following the loading of new data with .html() function

My website has a page that utilizes an ajax function to load data into the page. The ajax function is as follows: $(document).ready(function(){ function loadData(page){ $.ajax ...

ng-if is executed prior to the specified time

This unique Soundcloud player was created using Plangular, a directive that utilizes AngularJS and the Soundcloud API. Due to certain restrictions with third party apps not being able to stream some Soundcloud tracks, I have implemented ng-if="track" and n ...