前端 - 封裝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. javascript - node.js promise沒用2. golang - 用IDE看docker源碼時的小問題3. c++ - 如何正確的使用QWebEngineView?4. yii2中restful配置好后在nginx下報404錯誤5. javascript - js 寫一個正則 提取文本中的數(shù)據(jù)6. 算法 - python 給定一個正整數(shù)a和一個包含任意個正整數(shù)的 列表 b,求所有<=a 的加法組合7. android 如何實現(xiàn)如圖中的鍵盤上的公式及edittext的內(nèi)容展示呢8. java - 我在用Struts2上傳文件時,報以下錯誤怎么回事?9. php自學從哪里開始?10. 有會apicloud 混合開發(fā)的朋友嗎?
