2015-07-12 51 views
0

我想包括在使用Cal-HeatMap卡爾 - 熱圖 - 如何格式化日期和值subDomainText細胞

這裏同一小區日期和價值是什麼,我試圖做一個小提琴例子。 ...

[https://jsfiddle.net/paulrollings/6L36ajhn/12/][2] 

任何意見的幫助,非常感謝。感謝保羅

+0

您的jsFiddle在單元格中有日期和值。你在問怎麼把它們放在不同的線上? – Mark

+0

是的,這就是我想要做的。具有日期然後回車並在同一個單元格內的值低於全部。已嘗試日期+「\ r \ n」+ val也
&013;/ –

+0

我有一個快速的樣子。看起來文本是作爲SVG文本元素輸入的(在rect中的一個組中)。 SVG文本中的換行符不好玩,請參閱這裏:http://stackoverflow.com/questions/16701522/how-to-linebreak-an-svg-text-within-javascript ...所以我想你的手是相當捆綁。您可以分叉回購或提出問題。但首先我會推薦一些更多的研究:)祝你好運(\ n是javascript,
一個html標記...) –

回答

3

CalHeatMap呈現後,您可以砍它:

// wrap in timeout to let map render 
setTimeout(function(){ 
    var t = d3.selectAll('.subdomain-text') // find all the text blocks 
    .text(null); // blank them out 
    t.append('tspan') 
    .text(function(d){ 
     return new Date(d.t).getDate(); //append tspan with date 
    }) 
    .attr('x', function(d){ 
     return d3.select(this.parentNode).attr('x'); // steal parent x value so it stays in place 
    }); 
    t.append('tspan') 
    .text(function(d){ 
     return "€" + d.v; //append tspan with value 
    }) 
    .attr('dy','1.2em') 
    .attr('x', function(d){ 
     return d3.select(this.parentNode).attr('x'); // steal parent x value so it stays in place 
    }); 
}, 100); 

更新小提琴here

enter image description here