Highlight the related table entry when hovering over a slice of the donut chart in D3

Yesterday, I received some help to get my D3 code working with a donut chart. However, I have one quick question. The donut chart represents a JSON object and when you hover over certain parts of the chart, they animate and pop out. There's also a table that displays the same data. I managed to map the table entries so that hovering over them animates the corresponding pie chart slice. But now, I'm trying to do it the other way around - when you hover over the donut slice, it should highlight the table entry.

Currently, I've got it highlighting the entire table, but I'm struggling to map it to the correct individual table entry.

Here's a fiddle for context

This is my current arc mouseover function:

.on("mouseover", function(d) {
                    d3.select(this).select("path").transition()
                        .duration(100)
                        .attr("d", arcOver);
                    var path = paths[0][i];
    
                      d3.selectAll("#testtable .dataRow")
                        .style("background-color","red");  
    

If anyone could offer some guidance on how to correctly map to the table entry, I would greatly appreciate it!

Thank you!

Answer №1

To highlight both the pie chart and table simultaneously, you can use the index to achieve this:

.on("mouseover", function(d,i) {
    d3.select(this).select("path").transition()
        .duration(200)
        .attr("d", arcOver);
    var rowElement = d3.selectAll("#mytable .row")[0][i]; // i represents the index
    d3.select(rowElement)
        .style("background-color","blue");  
})

Check out the updated 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

How can I retrieve array responses for multiple HTML elements using a single AJAX call in PHP with Ajax post?

See page <button id='comparison_button'>Compare</button> <div id="sourceResponse"></div> <div id="destResponse"></div> <div id="missingResponse"></div> JS $(document).ready(function(){ $(&apo ...

Blend a background image using rgba without incorporating a gradient effect

Can you merge a background image with an rgba color without resorting to an rgba gradient? My current CSS3 style appears as follows: html { background: linear-gradient(rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0.75)), url("../icons/sombrero.jpg")no-repe ...

Error: The method 'editable' is not defined for the jQuery.jEditable object [object Object]

It seems like there is an error with this jeditable object. This is my webpage <script src="/assets/jquery.js?body=1" type="text/javascript"></script> <script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script> .. ...

Removing a post in Meteor-React using a submission modal is not possible as the post is not defined

After creating an additional submit modal for user confirmation when deleting a post from the collection, I'm facing difficulty in targeting the post. I also have a productivity query - should I include the DeletePost component in each post component ...

Running unit tests on the interceptor using axios results in an error

I'm currently working on writing Unit tests for my Nestapp. Specifically, I am focusing on the interceptor file and trying to create a test case that will throw an error when the condition error.message.indexOf('timeout') >= 0 is met, and ...

Data that is loaded asynchronously will not display rendered

I have async data loading via jayson from a server. After the data has finished loading, the boolean "loading" is set to false but my content does not re-render. Even though I can see on the console that the data was loaded correctly. var App = new Vue( ...

Switch between classes when hovering over / exiting ngFor elements

Displayed below is an element created using ngFor <span *ngFor="let picture of pictures; let i = index"> <a target="_blank" href="{{picture.image}}" class="thumbnail-display image-overlay"> <span class="overlay-icon hide"> ...

Create a variable called `myUInt8Array` of type `UInt

How can I declare a function parameter of type UInt8Array in TypeScript? import * as fs from "fs"; fs.readFile(fileName, (err: string, data: UInt8Array) => { if (err) { return console.error(err); } ...

Cease the act of sending submissions through JavaScript ajax requests

I need to prevent a form submission based on the result of an ajax request... Here is the code I attempted to implement: The chreg() function is supposed to return a boolean value from the ajax request, but it's not working! Javascript: function ch ...

Transform the JSON response from MongoDB into a formatted string

var db = mongoose.connection; const FoundWarning = db.collection('warning').find({UserID: Warned.user.id, guildID: message.guild.id}).toArray(function(err, results) { console.log(results); }) I have been attempting to ...

JavaScript Function Failing to Produce Output

I have created a function that reduces two numbers using the relationship of fractions. The function is working perfectly, but there is an issue with it not returning the value as expected. I have tried different approaches such as declaring a new variable ...

Using ajax to access the Wunderlist API and retrieve a list of tasks

I've been attempting to retrieve a list of tasks using the Wunderlist API, but I've encountered an issue with making the request via ajax. Interestingly, I can successfully execute the curl command from my terminal: curl -H "X-Access-Token: OAU ...

The issue persists with react-hook-form and Material UI RadioGroup as the selected value remains null

Having trouble with RadioGroup from Material UI when using react-hook-form Controller. I keep getting a null selected value, even though my code seems right. Can you help me figure out what's missing? import * as React from "react"; import { ...

Error in Background Image Validation for WCAG 2.0 AA Compliance

Our website does not meet wcag 2.0 AA standards when background images are turned off, likely due to the use of a dark background color. We still want to maintain our current dark background, but need a solution that switches the background to white if im ...

Understanding the Usage of FormData in NextJS

I'm trying to read fetch's body contents. Here's the code I'm using: fetch('/api/foo', { method: 'POST', body: new FormData(formRef.current), }); https://i.sstatic.net/6YB1V.png Now I need to parse the body dat ...

What is the process for implementing a version folder for my @types/definition?

Is there a way to access the typings for react-router in my project? My package.json file currently has this dependency: { "@types/react-router": "^4.0.3" } However, it seems to be using the standard index.d.ts file from DefinitelyTyped library which i ...

How can I choose a specific node within another node using selenium and xpath?

My webpage has a structure that looks like this: <div class="l_post j_l_post l_post_bright "...> ... <div class="j_lzl_c_b_a core_reply_content"> <li class="lzl_single_post j_lzl_s_p first_no_border" ...> <div ...

"Yakov's slender typefaces are appearing incorrectly on the screen

I recently tried to incorporate Yakov thin fonts using CSS @font-face, but I noticed that the fonts appear quite different from the original ones. Any idea why this might be happening? Below is the code snippet I used: @font-face { font-family:' ...

Vue looping through nested checkbox groups

Here is an object I am working with: rightGroups: [ { name: "Admin Rights", id: 1, rights: [ { caption: 'Manage Rights', name: 'reports', ...

How can I use nodejs to retrieve all data fields from a table except for one specific field?

Is there a way to fetch all fields data from a table without specifying the field names or creating a view? I have attempted the following SQL query: WITH orderschema as (SELECT array_to_string(ARRAY(SELECT c.column_name FROM information_schema.co ...