You have to use an array. That will store x
and y
like:
var coordinates= d3.mouse(this);
var x = coordinates[0];
var y = coordinates[1];
// D3 v4
var x = d3.event.pageX - document.getElementById(<id-of-your-svg>).getBoundingClientRect().x + 10
var y = d3.event.pageY - document.getElementById(<id-of-your-svg>).getBoundingClientRect().y + 10
Related Contents:
- What’s the best way to make a d3.js visualisation layout responsive?
- What is the difference D3 datum vs. data?
- How can I remove or replace SVG content?
- Resize svg when window is resized in d3.js
- D3.js: what is ‘g’ in .append(“g”) D3.js code?
- How to add a tooltip to an svg graphic?
- d3 axis labeling
- A good book for learning D3.js [closed]
- Invoke a callback at the end of a transition
- How do I save/export an SVG file after creating an SVG with D3.js (IE, safari and chrome)?
- Updating SVG Element Z-Index With D3
- D3 javascript Difference between foreach and each
- Protovis vs D3.js
- D3.js prepend (similar to jQuery prepend)
- D3 Appending Text to a SVG Rectangle
- Understanding how D3.js binds data to nodes
- D3.js: “Uncaught SyntaxError: Unexpected token ILLEGAL”?
- How to remove an attribute in D3.js?
- Convert a directory structure in the filesystem to JSON with Node.js
- x >= x pattern in JavaScript
- How can I bring a circle to the front with d3?
- How to select parent element of current element in d3.js
- Fix Node Position in D3 Force Directed Layout
- How do you create a family tree in d3.js?
- How to invoke “click” event programmatically in d3?
- How do I include newlines in labels in D3 charts?
- d3 js – loading json without a http get
- Appending multiple non-nested elements for each data member with D3.js
- D3, nested appends, and data flow
- how to format time on xAxis use d3.js
- How to set text color for my d3 chart title?
- D3: What is a Bisector?
- d3.js & nvd3.js — How to set y-axis range
- Can you insert a line break in text when using d3.js? [duplicate]
- How to center text in a rect element in d3?
- How to make force layout graph in D3.js responsive to screen/browser size
- How to get coordinates of an svg element?
- How to set multiple attributes with one value function?
- Attaching ‘onclick’ event to D3 chart background
- How to disable double click zoom for d3.behavior.zoom?
- How to render rectangles in a D3 grouped bar chart using React Faux DOM?
- d3 add multiple classes with function
- How to set the background-color of a D3.js svg?
- Accessing d3.js element attributes from the datum?
- Unclosed SVG path appears to be closed
- D3js take data from an array instead of a file
- Learning d3.js for data visualisation [closed]
- D3.js: Position tooltips using element position, not mouse position?
- D3: Removing Elements
- Label outside arc (Pie chart) d3.js