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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
sajal161292
Helper V
Helper V

Error while developing a custom visual in power bi using d3

Hi,

 

I am facing an error while creating a simple bar chart using d3 

 

Error message:  Namespace '"C:/Users/hasingh/node_modules/@types/d3/index"' has no exported member 'selection'

 

This is not getting fixed.

 

Please find my d3 code here:

 

module powerbi.extensibility.visual {

interface BarChartViewModel {
dataPoints: BarChartDataPoint[];
dataMax: number;
};

 

interface BarChartDataPoint {
value: number;
category: string;
};

 

 

export class Visual implements IVisual {
private svg: d3.Selection<d3.BaseType, any, HTMLElement, any>;
private host: IVisualHost;
private barGroup: d3.selection<SVGAElement>;

constructor(options: VisualConstructorOptions) {

this.host = options.host;

this.svg = d3.select<SVGElement, any>(options.element as any)
.append("svg")
.classed("my bar chart", true);
this.barGroup = this.svg.append("g")
.classed("bar-group", true);
}

public update(options: VisualUpdateOptions) {

let testData: BarChartDataPoint[] = [
{
value: 10,
category: 'a'
},
{
value: 20,
category: 'b'
},
{
value: 1,
category: 'c'
},
{
value: 100,
category: 'd'
},
{
value: 500,
category: 'e'
}];

let viewModel: BarChartViewModel = {
dataPoints: testData,
dataMax: d3.max(testData, x => x.value)
};
let width = options.viewport.width;
let height = options.viewport.height;

console.log(typeof (width));

this.svg.attr({
width: width,
height: height
});

let yScale = d3.scaleLinear()
.domain([0, viewModel.dataMax])
.range([height, 0]);

let xScale = d3.scaleOrdinal()
.domain(viewModel.dataPoints.map(d => d.category))
.rangeBands([0, width]);


let bars = this.barGroup
.selectAll(".bar")
.data(viewModel.dataPoints);

bars.attr({
width: xScale.rangeBand(),
height: d => height - yScale(d.value),
y: d => yScale(d.value),
x: d => xScale(d.category)
});

bars.exit().remove();
}

}


}

1 REPLY 1
v-chuncz-msft
Community Support
Community Support

@sajal161292,

 

The word "Selection" needs to be capitalized.

 

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.