d3.js悬停工具提示未在Power BI中呈现

时间:2020-10-20 15:48:22

标签: css d3.js powerbi tooltip

我有一个使用d3构建的散点图。在浏览器中进行测试时,我已经获得了可以正常使用的工具提示,但是在power bi中构建了相同的d3可视化效果时,却无法将鼠标悬停在某个点上来渲染工具提示?是否还有其他人遇到过此问题,或者在其他地方使用power bi记录了此问题?提前致谢。我从此处构建的示例在这里:

https://www.d3-graph-gallery.com/graph/scatter_basic.html

var margin = {top: 10, right: 30, bottom: 30, left: 80},
width = pbi.width - margin.left - margin.right,
height = pbi.height - margin.top - margin.bottom;



// ALTER: Replaced the d3.tsv function with the pbi variant: pbi.dsv
pbi.dsv(function(letters) {

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 + ")");


// Add the tooltip container to the vis container
        // it's invisible and its position/contents are defined during mouseover
    var tooltip = d3.select("#chart").append("div")
        .attr("class", "tooltip")
        .style("opacity", 0);





var x = d3.scale.linear()
.domain([0, 4000])
.range([0, width]);

var y = d3.scale.linear()
.domain([0, 500000])
.range([height, 0]);




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.append('g')
.selectAll("dot")
.data(letters)
.enter()
.append("circle")
  .attr("cx", function (d) { return x(d.grlivarea); } )
  .attr("cy", function (d) { return y(d.saleprice); } )
  .attr("r", 1.5)
  .style("fill", "#69b3a2")
.on("mouseover", function(data) {
            d3.select(this).attr("r", 5)
            d3.select(this).style("stroke", "000000")
            d3.select(this).style("stroke-width", "2px")
            d3.select('.tooltip')
            tooltip.transition()
                .duration(200)
                .style("opacity", .8);
            tooltip.html("tooltip!")
                
        })


.on("mouseout", function(data) {
                d3.select(this).attr("r", 1.5)
                d3.select(this).style("stroke", "000000")
                d3.select(this).style("stroke-width", "0px")
            
        })


});

CSS:

  body {
    font: 10px sans-serif;
}



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

.tooltip {
    word-wrap: normal;
    position: absolute;
    text-align: center;
    min-height: 20px;
    min-width: 30px;                      
    padding: 2px;               
    font: 14px;      
    color: #fff;
    background-color: rgba(51,51,51,.85);
    border: solid thin black;

 }

    .tooltip.show {
    opacity: 0.9;
} 

0 个答案:

没有答案