现在已经为此花了一段时间,需要另一双眼睛。
我正在尝试在Power BI中创建一个新的自定义外观,它是量规外观,但是允许使用不同的颜色填充量规。一切正常,一件事!这就是根据Power BI设置的值将格式应用于要显示的值。当我调用valueFormatter.format(123)函数时,我的自定义外观消失了,PBIVIZ没有报告任何错误。
Visual.TS
enter code module powerbi.extensibility.visual {
"use strict";
import ValueFormatter = powerbi.extensibility.utils.formatting.valueFormatter;
import IValueFormatter = powerbi.extensibility.utils.formatting.IValueFormatter;
export class Visual implements IVisual {
private host: IVisualHost;
private svg: d3.Selection<SVGElement>;
private container: d3.Selection<SVGElement>;
private textValue: d3.Selection<SVGElement>;
private visualSettings: VisualSettings;
constructor(options: VisualConstructorOptions) {
this.svg = d3.select(options.element)
.append('svg')
.classed('circleCard', true);
this.container = this.svg.append("g")
.classed('container', true);
this.textValue = this.container.append("text")
.classed("textValue", true);
}
public update(options: VisualUpdateOptions) {
let dataView: DataView = options.dataViews[0];
this.visualSettings = VisualSettings.parse<VisualSettings>(dataView);
// Grab the width and height of the element.
let width: number = options.viewport.width;
let height: number = options.viewport.height;
// Set the width and height of element to the SVG viewport.
this.svg.attr({
width: width,
height: height
});
// Height, width and radius of the gauge
let tWidth: number = width / 2;
let tHeight: number = height - 1;
let radius: number = height;
// Make sure the gauge fits within the view.
if (radius > (width / 2))
radius = tWidth;
// Define the inner and outer radius of the gauge.
let oRadius: number = radius;
let iRadius: number = radius / 1.5;
// Trying to format the number! :(
let valueFormatter: IValueFormatter = ValueFormatter.create({
format: "0.00"
});
// Commenting out this line makes it work!
console.log(valueFormatter.format(123));
// Display the value used for the arc calculation.
this.textValue
.text("69.8%")
.attr({
x: '50%',
y: tHeight - (iRadius / 3),
dy: '0.35em', 'text-anchor': 'middle'
}).style({
'font-size': (iRadius / 30) + 'em',
'font-family': 'Arial',
'fill': '#ffffff'
});
}
private static parseSettings(dataView: DataView): VisualSettings {
return VisualSettings.parse(dataView) as VisualSettings;
}
/**
* This function gets called for each of the objects defined in the capabilities files and allows you to select which of the
* objects and properties you want to expose to the users in the property pane.
*
*/
public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstanceEnumeration {
const settings: VisualSettings = this.visualSettings || VisualSettings.getDefault() as VisualSettings;
return VisualSettings.enumerateObjectInstances(settings, options);
}
}
}
现在,如果我注释掉控制台行,则会显示该文本,并且不添加注释,该文本将不会显示。我遵循了“ powerbi-visuals-utils-formattingutils”的安装指南。
有人能解释为什么会这样吗?大概我想说一个库之间的不兼容问题,但这是PBIVIZ未能解决的问题。