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


框架用的是angularjs,我在directive指令里面封裝了一個(gè)函數(shù)
function dataFormat() {var tooltipFormatValue = [];tooltipFormatValue[0] = {’$’:d3.format('$')};tooltipFormatValue[1] = {’thousands separator’:d3.format('s')};//千位符tooltipFormatValue[2] = {’precision’:d3.format('.2f')};//精確小數(shù)點(diǎn)后面兩位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í)設(shè)定$和千位符格式?2.不知道我的函數(shù)思路對(duì)不對(duì),目前思緒很混亂**
問(wèn)題解答
回答1:1.怎么同時(shí)設(shè)定$和千位符格式?d3.format(’$,’)(value)
相關(guān)文章:
1. 如何設(shè)置一個(gè)無(wú)限循環(huán)并打破它。(Java線程)2. php對(duì)mysql提取數(shù)據(jù)那種速度更快3. shell - mysql更新錯(cuò)誤4. DADB.class.php文件的代碼怎么寫(xiě)5. 網(wǎng)頁(yè)爬蟲(chóng) - 如何使用使用java抓取信息并制作一個(gè)排名系統(tǒng)?6. macos - 如何徹底刪除mac自帶的apache和php7. javascript - immutable配合react提升性能?8. python小白 自學(xué)看書(shū)遇到看不懂的地方9. mysql - 在log日志中已知用戶的某一步操作,如何獲取其上一步操作?10. javascript - sublime快鍵鍵問(wèn)題

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