Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
giorgikok
Frequent Visitor

Bar Chart Interactivity on click

Hello, I am trying to add chart interactivity and I've run into a problem. The selectionID of my chart that is kept in dataPoints does not seem to return correctly. After looking around and loggin the console I have found out that the datapoint being returned isn't of a regular type, it returns a t object with some cursor elements and the actual target rect.bar (+ a same looking srcElement). I was wondering if this is the correct approach and if so how would I access the selectionID of the individual bar in the bar chart?    
Here's the code:
Spoiler
.on('click', (dataPoint) => {

         console.log("CLICK DATA: ", dataPoint);
         console.log("CLICK DATA TARGET: ", dataPoint.target);
         console.log("CLICK DATA TARGET DATA: ", dataPoint.target.data);
         console.log("CLICK DATA TARGET DATA SELECTION ID: ", dataPoint.target.data.SelectionId.getKey());

        //const selected = !this.selectionManager.hasSelection();
        console.log("UPDATE SELECTION ID: ", dataPoint.selectionId);
        console.log("UPDATE SELECTION ID GETKEY: ", dataPoint.selectionId.getKey());
        if (!dataPoint.selectionId) {
            console.error("SelectionId is undefined for data point:", dataPoint);
            return;
        }
        this.selectionManager
            .select(dataPoint.selectionId, false)
            .then((ids: ISelectionId[]) => {
                this.syncSelectionState(barSelectionMerged, ids);
                barSelectionMerged.style("fill", (d: BarChartDataPoint) => {
                    return ids.length > 0 && dataPoint.selectionId.equals(dataPoint.selectionId) ? "#7ACA00" : "#AAAAAA";
                });
            });
    });
 
1 ACCEPTED SOLUTION
giorgikok
Frequent Visitor

figured it out: 

 

const clickData = d3.select(d.target).datum() as { selectionId: ISelectionId };

this is how you get the selectionId

View solution in original post

1 REPLY 1
giorgikok
Frequent Visitor

figured it out: 

 

const clickData = d3.select(d.target).datum() as { selectionId: ISelectionId };

this is how you get the selectionId

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.