2016-01-22 66 views
-1

使用D3和打字稿是不是很難從HTML ...如何動態地在雙向電力創建打字稿表

例子我創建 -

<table id="view"> 
    <thead> 
    </thead> 
    <tbody> 
    </tbody> 
</table> 

打字稿

// the table rows, typically loaded from data file using d3.csv 
    var hours = [ 
     { title: "Fredrik", one: 8, two: 5, three: 6, four: 9, five: 5, six: 8, seven: 8, eight: 0, nine: 8, ten: 12 }, 
     { title: "Yoakim", one: 4, two: 6, three: 8, four: 3, five: 8, six: 4, seven: 2, eight: 1, nine: 7, ten: 10 }, 
     { title: "Lars", one: 8, two: 12, three: 6, four: 8, five: 5, six: 8, seven: 8, eight: 10, nine: 8, ten: 13 }, 
    ]; 

    // column definitions 
    var columns = [ 
     { head: 'UserName', cl: 'title', html: ƒ('title') }, 
     { head: 'one', cl: 'center', html: ƒ('one') }, 
     { head: 'two', cl: 'center', html: ƒ('two', two()) }, 
     { head: 'three', cl: 'num', html: ƒ('three', d3.format('$,')) }, 
     { head: 'four', cl: 'num', html: ƒ('four', d3.format('.1f')) }, 
     { head: 'five', cl: 'num', html: ƒ('five', d3.format('$,')) }, 
     { head: 'six', cl: 'num', html: ƒ('six', d3.format('.1f')) }, 
     { head: 'seven', cl: 'num', html: ƒ('seven', d3.format('$,')) }, 
     { head: 'eight', cl: 'num', html: ƒ('eight', d3.format('.1f')) }, 
     { head: 'nine', cl: 'num', html: ƒ('nine', d3.format('$,')) }, 
     { head: 'ten', cl: 'num', html: ƒ('ten', d3.format('.1f')) } 
    ]; 

    // create table 
    var table = d3.select('body') 
     .append('table'); 

    // create table header 
    table.append('thead').append('tr') 
     .selectAll('th') 
     .data(columns).enter() 
     .append('th') 
     .attr('class', ƒ('cl')) 
     .text(ƒ('head')); 

    // create table body 
    table.append('tbody') 
     .selectAll('tr') 
     .data(hours).enter() 
     .append('tr') 
     .selectAll('td') 
     .data(function(row, i) { 
      return columns.map(function(c) { 
       // compute cell values for this specific row 
       var cell = {}; 
       d3.keys(c).forEach(function(k) { 
        cell[k] = typeof c[k] == 'function' ? c[k](row,i) : c[k]; 
       }); 
       return cell; 
      }); 
     }).enter() 
     .append('td') 
     .html(ƒ('html')) 
     .attr('class', ƒ('cl')); 

    function two() { 
     var fmt = d3.format('02d'); 
     return function(l) { return Math.floor(l/60) + ':' + fmt(l % 60) + ''; }; 
    } 

CSS

<style type="text/css"> 
    view, td, th { 
    height:50; 
} 

th { 
background-color:black; 
    color:white 
} 

td { 
    border: 1px solid black; 
    background-color:#ccc; 
    width:200px; 
    text-align: center; 

} 
    </style> 

這裏是jsFiddle:https://jsfiddle.net/christoferhansen/dpuk9n55/1/

現在我的問題是我怎樣才能在Power BI環境中使用相同的結構,並獲得類似的結果!

任何人都知道這個問題的任何答案!

+0

分享你嘗試過的一些代碼,也許你的數據樣本會有所幫助。 :) – toskv

+0

這個問題太廣泛了。目前還不清楚'動態表'是什麼或者'動態創建TypeScript表'的含義。正如托斯卡夫所提到的,如果您提供了您想要實現的樣本或範例,我們可能會指出您朝着正確的方向發展。 –

+0

@LukaszP。已更新問題 –

回答

1

建議您查看Power BI dev tools中加載的默認視覺效果。只需按「編譯並運行」即可在加載時查看它。它在Power BI中的數據集上實現一個表格,您將看到代碼結構以及所需的內容。您需要註冊Power BI才能訪問bi bi。

+0

感謝您的回答,但在開發工具中沒有調試器可用,所以不可能看到我做錯了什麼,這就是爲什麼我想在Visual Studio中工作的原因,但在那裏我看不到我的插件列表名稱... –

+0

這裏是這個問題http://stackoverflow.com/questions/34993944/uncomment-it-to-see-your-plugin-in-powerbivisualsplayground-plugins –

+1

在瀏覽器你應該使用內置的瀏覽器調試器。最好的方法是堅持「調試器」的說法。在你的init函數中。然後按F12(大多數瀏覽器將啓動它們的調試器)。當你按'編譯+運行'時,調試器會破壞你的init函數。在導出視覺效果並且您想在Power BI Web UI中對其進行測試後,此功能仍然有效。就我個人而言,我比VS中的調試更好,但可能是個人偏好。 –