2014-05-12 113 views
0

我正在嘗試將一個磅符號添加到NVD3軸標籤。d3.js&NVD3 axisLabel用英鎊(英鎊)符號

以下做工作:

chart.yAxis.axisLabel('£') 

這不

chart.yAxis.axisLabel('£') 

不知道如果有一個簡單的解決方案或者這是否是一個NVD3或D3限制。

我想我會實施一些手動hack來修復它(例如,不只是用NVD3繪製軸標籤),但不知道如何繼續?

  • D3版本:3.1.5
  • nvd3版本:1.1.15b

更新:原來的問題是編輯(ACE)我用正在刪除£符號,與d3或nvd3無關。

回答

1

試試這個

chart.yAxis.tickFormat(function(d) { 
    var format = d3.format(",d"); 
    return '£ ' + format(d) 
}); 

OR

chart.yAxis.tickFormat(function(d) { 
    return '£ ' + d 
}); 

希望它能幫助。

+0

感謝這是數字的格式,而不是標籤,因爲你可以看到上面的結果是我有一個單獨的問題。 – SColvin

0
chart.yAxis.tickFormat = function(d) { 
    //Retuns currency formatted string with pound sign 
    // d3.format('c')(163) --> To Convert unicode 
    return d3.format('c')(163) + ' ' + d3.format(',.2f')(d); 
}