前端 - 封裝d3的data.format功能遇到問題
問題描述
在使用c3.js的tooltip.format.value功能的時候碰到一些問題,需要自己封裝一個函數(shù),DOM中直接呈現(xiàn)一個下拉列表,用戶可以選擇值來設(shè)定format有四個選項,$,千位符,精確到小數(shù)點兩位或者其他位,同時設(shè)置$和千位符($6789,000)


框架用的是angularjs,我在directive指令里面封裝了一個函數(shù)
function dataFormat() {var tooltipFormatValue = [];tooltipFormatValue[0] = {’$’:d3.format('$')};tooltipFormatValue[1] = {’thousands separator’:d3.format('s')};//千位符tooltipFormatValue[2] = {’precision’:d3.format('.2f')};//精確小數(shù)點后面兩位tooltipFormatValue[3] = {’$ and thousands separator’: d3.format('$ | currency: $')};//帶$和千位符console.log(tooltipFormatValue)d3.format = { value: function(value,id,name) { var format = id === name ? d3.format(’,’):d3.format(’,’); return format(value); }} }
**1.怎么同時設(shè)定$和千位符格式?2.不知道我的函數(shù)思路對不對,目前思緒很混亂**
問題解答
回答1:1.怎么同時設(shè)定$和千位符格式?d3.format(’$,’)(value)
相關(guān)文章:
1. boot2docker無法啟動2. 關(guān)于docker下的nginx壓力測試3. java - SSH框架中寫分頁時service層中不能注入分頁類4. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.5. mac里的docker如何命令行開啟呢?6. node.js - antdesign怎么集合react-redux對input控件進(jìn)行初始化賦值7. 為什么我ping不通我的docker容器呢???8. 老師,按tab鍵不起作用怎么回事9. docker鏡像push報錯10. dockerfile - 為什么docker容器啟動不了?

網(wǎng)公網(wǎng)安備