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

  • Home
  • SEARCH
  • 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 9174189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:42:49+00:00 2026-06-17T16:42:49+00:00

I am using D3, and trying to add a text label above an element

  • 0

I am using D3, and trying to add a text label above an element that has undergone a rotational transform. My problem is how to position the text without actually rotating it too.

These are the original elements:

var circle = g.selectAll('.city')
 .data(data).enter()
 .append('circle')
 .attr('class', 'city')
 .attr('r', 10)
 .attr("cy", 0)
 .attr("cx", function(d) {
    return rdist(d.dist);
 }).attr("transform", function(d, i) {
    return "rotate(" + d.radial_pos + " 0 0)";
 });

And this is how I append the text, on mouseover:

circle.on("mouseover", function(d) {
  var cx = d3.select(this).attr('cx');
  var cy = d3.select(this).attr('cy');
  var label = d3.select(this.parentNode)
  .append('text')
  .text(function(d) {
    return d.name;
  }).attr('x', function() {
    return cx;
  }).attr('y', function() {
    return cy;
  }).attr("transform", function() {
    return "rotate(" + d.radial_pos + " 0 0)";
  });
});

This returns the labels in the right position, but the whole label is rotated, so the text is at an angle.

Is there some way that I can first transform the coordinates themselves, then set the text to those coordinates, so it remains the right way up? Alternatively, can I get the rendered position of the circle somehow?

  • 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-17T16:42:50+00:00Added an answer on June 17, 2026 at 4:42 pm

    It seems that removing the spurious transform attribute with rotation on the text element should solve the problem as shown in this jsFiddle :

    circle.on("mouseover", function(d) {
      var cx = d3.select(this).attr('cx');
      var cy = d3.select(this).attr('cy');
      var label = d3.select(this.parentNode)
      .append('text')
      .text(function(d) {
        return d.name;
      }).attr('x', function() {
        return cx;
      }).attr('y', function() {
        return cy;
      });
    });
    

    PS: I am assuming this is related to the question: D3.js: how to append elements when data is already bound?

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

Sidebar

Related Questions

I'm trying yo add text to the editor using some buttons, So actualy I've
I'm trying to add some HTML formatted text to Word using Office Interop. My
I am trying to change a label's text by using server-side JavaScript (onclick) and
I trying to add an break before an element in css without changing the
I'm trying to 'add a link' functionality to my site. For that I'm using
Good day. I am trying to fetch an asp.net label control's text value using
How can I add a label to my navigation bar that has the same
I'm using (trying to use) jQuery to add a class to the first paragraph
Trying to add a class object into a List using reflection, but when invoking
I am trying to add an attribute using javax.xml.bind.annotation to a simple type (String

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.