前端 - 封裝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. bootstrp是col-md-12列的,只有col-md-10有內(nèi)容,可以讓沒(méi)有內(nèi)容的不占據(jù)位置嗎;2. 常量在外面不加引號(hào)會(huì)報(bào)錯(cuò)。3. wordpress里,這樣的目錄列表是屬于小工具還是啥?4. android - Genymotion 微信閃退 not find plugin.location_google.GoogleProxyUI5. python如何設(shè)置一個(gè)隨著系統(tǒng)時(shí)間變化的動(dòng)態(tài)變量?6. 百度地圖 - Android app中準(zhǔn)備接入地圖sdk,百度VS高德哪個(gè)好一點(diǎn)?7. 我的怎么不顯示啊,話說(shuō)有沒(méi)有QQ群什么的8. mysql federated引擎無(wú)法開(kāi)啟9. MySQL 使用 group by 之后然后 IFNULL(COUNT(*),0) 為什么還是會(huì)獲得 null10. sublime text3安裝package control失敗
