在Power BI Custom可视图中清除相应的数据字段后,如何使D3文本元素消失?

问题描述

我正在使用D3库开发一个简单的Power BI自定义视觉对象,以显示拖到Text元素上的度量字段中的数据字段的值。当将文本元素拖到度量字段中时,它会正确显示数据字段的值。但是在删除数据字段之后,text元素中的值应该消失,不幸的是不会发生。我在文本元素的末尾添加.exit().remove(),但是即使这样也不能解决问题。

我在下面粘贴了部分代码,所涉及的文本元素为this.textValue

请提出您的建议。

public update(options: VisualUpdateOptions) {

    let dataView: DataView = options.dataViews[0];



    let width: number = options.viewport.width;
    let height: number = options.viewport.height;
    this.svg.attr("width",width);
    this.svg.attr("height",height);

    this.visualSettings = VisualSettings.parse<VisualSettings>(dataView);

    this.visualSettings.card.cardThickness = Math.max(0,this.visualSettings.card.cardThickness);
    this.visualSettings.card.cardThickness = Math.min(10,this.visualSettings.card.cardThickness);
    let a: boolean = this.visualSettings.labels.Visibility;
    let b: boolean = this.visualSettings.card.textbold;
    var formatComma = d3.format(",")
    var catarrlength = dataView.categorical.categories.values.length


    this.rect
        .style("fill",this.visualSettings.card.cardColor)
        .attr("x","50%")
        .attr("y","0%")
        .style("fill-opacity",1)
        .style("stroke","black")
        .style("stroke-width",this.visualSettings.card.cardThickness)
        .attr("width",width / 2)
        .attr("height",height / 3)

    //this.rect.exit().remove();

    //let fontSizeValue: number = Math.min(width,height) / 5;   

    

    this.textValue
        .text(<string>dataView.categorical.values[0].values[0])
        .attr("x","75%")
        .attr("y",height / 6)
        .attr("dy","0.0em")
        .attr("text-anchor","middle")
        .attr("font-family",this.visualSettings.card.fontfamily)
        .attr("font-size",this.visualSettings.card.fontSize)
        .style("fill",this.visualSettings.card.fontcolor)


    //.exit().remove()
    this.textValue.exit().remove();

 }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...