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
AmiraB
Frequent Visitor

Custom Visuals- How to move text when resizing chart

I tried adding text to the Sample Bar Chart code

         bars.enter()
                .append("text")
                .classed("label",true) //or "label"
                .attr ("y",d => yScale(<number>d.value)+1)
                .attr ("x",d => xScale(d.category)+xScale.rangeBand()/2)
                .attr("text-anchor", "middle")
             // .attr("font-size", "10000000.5em")
                .attr("fill", "red")
                .text(d => <string>d.value)
                ;

 

The issue is this text do not move when I resize the chart

1 ACCEPTED SOLUTION
AmiraB
Frequent Visitor

This solved the issue .

            let text = this.barContainer.selectAll('.bar').data(viewModel.dataPoints);

            text.enter()
                .append('text')
                .classed('bartext', true)
                .text(d => <string>d.value2);
            text.attr({
                y: d => height - 15,
                x: d => xScale(d.category) + xScale.rangeBand() / 2,
                'text-anchor': "middle",
                fill: "red"
            });

View solution in original post

2 REPLIES 2
AmiraB
Frequent Visitor

This solved the issue .

            let text = this.barContainer.selectAll('.bar').data(viewModel.dataPoints);

            text.enter()
                .append('text')
                .classed('bartext', true)
                .text(d => <string>d.value2);
            text.attr({
                y: d => height - 15,
                x: d => xScale(d.category) + xScale.rangeBand() / 2,
                'text-anchor': "middle",
                fill: "red"
            });

@AmiraB,

 

Glad to hear that you've solved this problem and thank you for sharing the solution. This might be beneficial to other community members, you could help mark it as answer.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.