Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
Issue showing bar chart with D3 js in Power PI

I have tried putting in the D3 js codes and styling and have added the dataset as shown in the picture below. However, the bar chart don't show in Power BI.The dataset type I am using is a text file (.txt)

enter image description here

These are the D3 js for the bar chart.

var margin = {top: 20, right: 20, bottom: 30, left: 40},
    width = pbi.width - margin.left - margin.right,   // ALTER: Changed fixed width with the 'pbi.width' variable
    height = pbi.height - margin.top - margin.bottom; // ALTER: Changed fixed height with the 'pbi.height' variable

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")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

// ALTER: Replaced the d3.tsv function with the pbi variant: pbi.dsv
pbi.dsv(type, function(letters) {
    x.domain(letters.map(function(d) { return d.letter; }));
    y.domain([0, d3.max(letters, function(d) { return d.frequency; })]);

    svg.append("g")
        .attr("class", "x axis")
        .attr("transform", "translate(0," + height + ")")
        .call(d3.svg.axis().scale(x).orient("bottom"));

    svg.append("g")
        .attr("class", "y axis")
        .call(d3.svg.axis().scale(y).orient("left"));

    svg.selectAll(".bar")
        .data(letters)
        .enter()
        .append("rect")
        .style("fill", pbi.colors[0]) // First color of provided color array
        .attr("x", function(d) { return x(d.letter); })
        .attr("width", x.rangeBand())
        .attr("y", function(d) { return y(d.frequency); })
        .attr("height", function(d) { return height - y(d.frequency); });
});

function type(d) {
    d.frequency = +d.frequency;
    return d;
}
These are the CSS for the bar chart.

body {
    font: 10px sans-serif;
}

.axis path,
.axis line {
    fill: none;
    stroke: #000;
    shape-rendering: crispEdges;
}

.x.axis path {
    display: none;
}

I have tried to use the above D3 js and CSS codes, however, I don't know why does the bar chart not appear in Power BI.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda