Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8801737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:54:40+00:00 2026-06-14T00:54:40+00:00

I am trying to setup a tooltip for an area path that I created.

  • 0

I am trying to setup a tooltip for an area path that I created. I checked all the arguments being passed into the on mousemove event handler, and I’m just getting the full data set, 0, 0. Nothing to indicate my index in the data as far as I can see. “This” context also is the svg path element. Still nothing useful. Even looked at d3.select(this), and I can’t find the index anywhere there either. Is there some way to determine over which data point my mouse is?

Looking around I found a reference to d3.mouse(this), and that gives me x/y coordinate, but how do I map that back to a data point in the data set?

My goal is to have a tooltip to display some meta-data related to that specific data point in the set.

Here is are some code snippets as requested:

var area=d3.svg.area()
    .interpolate("monotone")
    .x(function(d){
      return(scale.x(d.date));
    })
    .y0(height-padding.bottom)
    .y1(function(d){
      return(scale.y(d.count));
    });

var path=svg.append('path')
            .datum(data)
            .attr('d',area)
            .attr("clip-path", "url(#clip)")
            .attr('fill','url(#gradient)')
            // .attr('title','path')
            .on('mousemove',function(){
              console.log(arguments);
              console.log(d3.select(this));
              console.log(d3.mouse(this));        
            });          
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:54:41+00:00Added an answer on June 14, 2026 at 12:54 am

    Your problem is not so much related to the mouseover event listener, but more to the way you bind data to your path; you don’t do a proper data join.

    Read more about data joins: http://bost.ocks.org/mike/join/

    The following example is using divs instead of paths, but the principle is the same. See working example at: http://jsfiddle.net/RghQn/

    var data = ['a', 'b', 'c'];
    d3.select("body").selectAll("div")
        .data(data)
      .enter().append("div")
        .text(String)
        .on("mouseover", function(d,i) {
            console.log("mouseover!");
            // d: bound datum to DOM element
            console.log("d: ", d);
            // i: index of the selection
            console.log("i: ", i);
            // this context: the current DOM element
            console.log(d3.select(this).text());
        });
    ​​​​​​​​​​​​​​​
    

    See also the API docs section about event listeners: https://github.com/mbostock/d3/wiki/Selections#wiki-on

    selection.on(type[, listener[, capture]])

    Adds or removes an event listener to each element in the current
    selection, for the specified type. The type is a string event type
    name, such as “click”, “mouseover”, or “submit”. The specified
    listener is invoked in the same manner as other operator functions,
    being passed the current datum d and index i, with the this context as
    the current DOM element. To access the current event, use the global
    d3.event.


    EDIT

    I know realize I misunderstood your question. You have one path and want to get information about the path coordinates at the location of the mouse.

    There is not straightforward. You can see how Mike did it in the following example: http://bl.ocks.org/3902569

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to setup a SQL stored procedure that if the variable passed to it
I'm trying setup a map that displays different pin colors depending on the type/class
I'm trying setup costum storege. Looks like all is ok. But there is the
In trying to setup a unit test for inserting an item into an SQL
I'm trying setup a Rails app that will be something like a game. The
Trying to setup Rails environment on OS X. When I run rvm reinstall all
Trying to setup a Cron task that gets a file via FTP however seems
Im trying to setup so that when you hover over class .object1 -> in
Im trying to setup a program that will accept an incoming email and then
Trying to setup a page that auto updates based on the users date/time. Need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.