Microstrategy使用可视化作为选择器D3 costum chart

Bru*_*ira 6 javascript microstrategy d3.js

我正在尝试使用可视化作为D3服装图表上的选择器.我正在关注SDK文档在这里,我不能让我的示例工作.

基本上我通过声明"me"var并启用"用作过滤器"选项来加注星标.

var me = this;
this.addUseAsFilterMenuItem();
Run Code Online (Sandbox Code Playgroud)

然后,当附加de svg元素时,我添加了clear和end selecion方法:

var g = d3.select(this.domNode).append("svg")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
    .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")")
    .on("click", function(d) {
        if (event.target.classList.contains('bar')) {
            me.clearSelections();
            me.endSelections();
            return true;
        } else {
            return true;
        }
     });
Run Code Online (Sandbox Code Playgroud)

获取数据时,我使用hasSelection属性:

var data = this.dataInterface.getRawData(mstrmojo.models.template.DataInterface.ENUM_RAW_DATA_FORMAT.TREE, {
  hasSelection: true
 }).children;
Run Code Online (Sandbox Code Playgroud)

在我的栏上添加"applyselection"方法时:

 g.selectAll(".bar")
.data(data)
.enter()
.append("rect")
.attr("class", "bar")
.attr("x", function(d) {
    return x(d.name);
})
.attr("y", function(d) {
    return y(d.value);
})
.attr("height", function(d) {
    return height - y(d.value);
})
.attr("width", x.rangeBand())
.style("fill", function(d) {

})
.on("click", function(d) {
    me.applySelection(d.selection);
});
Run Code Online (Sandbox Code Playgroud)

但它不起作用.我设法在条形码点击事件上控制d.selection,我是unifined.

有人可以帮个忙吗?

谢谢.

Bru*_*ira 2

在花费了很多时间之后,我能够找出我的代码出了什么问题。选择方法必须这样调用:

.on("click", function(d, i) {
    me.applySelection(data[i].attributeSelector);
    return true;
});
Run Code Online (Sandbox Code Playgroud)