I want to create a line chart for the following data in powerbi custom visual d3.js
enter image description here
I’ve tried follwing code , but I’m getting a blank visual.Are there any latest resources for creating visuals in d3.js.
var margin = {top: 50, right: 50, bottom: 50, left: 50};
// Calculate the width and height of the chart area
var width = pbi.width - margin.left - margin.right;
var height = pbi.height - margin.top - margin.bottom;
// Define x and y scales
var x = d3.scale.ordinal()
.rangeRoundBands([0, width], 0.1, 0.2);
var y = d3.scale.linear()
.range([height, 0]);
var svg = d3.select("#chart")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g") // Append a 'g' element for grouping
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
pbi.dsv(type, function(Names) {
// Set the domain for x and y scales based on data
x.domain(Names.map(function(d) { return d.Name; }));
y.domain([0, d3.max(Names, function(d) { return d.Marks; })]);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x));
// Append y axis
svg.append("g")
.attr("class", "y axis")
.call(d3.axisLeft(y));
// Append bars
svg.selectAll(".bar")
.data(data)
.enter()
.append("rect")
.attr("class", "bar")
.attr("x", function(d) { return x(d.Name); })
.attr("width", x.bandwidth())
.attr("y", function(d) { return y(d.Marks); })
.attr("height", function(d) { return height - y(d.Marks); })
.style("fill", pbi.colors[0]);
});
function type(d) {
d.Marks = +d.Marks;
return d;
}