2017-03-15 22 views
6

我試圖使用可視化作爲D3 costum圖表上的選擇器。我正在關注SDK文檔在這裏,我不能讓我的例子工作。Microstrategy使用可視化作爲選擇器D3 costum圖表

基本上,我通過聲明「我」var並啓用「用作過濾器」選項。

var me = this; 
this.addUseAsFilterMenuItem(); 

然後,追加德SVG元素的時候,我添加了明確和最終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; 
     } 
    }); 

當獲取數據我使用hasSelection屬性:

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

和添加時我的酒吧上的「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); 
}); 

但它不起作用。我管理控制檯上的d.selection欄單擊事件,我這是不解決的。

有人可以幫我一下嗎?

謝謝。

回答

2

在我花了很多時間在這之後,我能夠發現我的代碼出了什麼問題。選擇方法必須如下所示:

.on("click", function(d, i) { 
    me.applySelection(data[i].attributeSelector); 
    return true; 
}); 
相關問題