一段时间以来一直在打我自己,需要另一双眼睛 .
我试图在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没有采用的东西 .