前端 - 封裝d3的data.format功能遇到問題
問題描述
在使用c3.js的tooltip.format.value功能的時(shí)候碰到一些問題,需要自己封裝一個(gè)函數(shù),DOM中直接呈現(xiàn)一個(gè)下拉列表,用戶可以選擇值來設(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ì),目前思緒很混亂**
問題解答
回答1:1.怎么同時(shí)設(shè)定$和千位符格式?d3.format(’$,’)(value)
相關(guān)文章:
1. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題2. html5 - 這個(gè)代碼顯示功能如何實(shí)現(xiàn)?3. java - 關(guān)于File的問題?4. java - instance method中 static后的<K>是什么意思?5. docker - 如何修改運(yùn)行中容器的配置6. 錯(cuò)誤:java.lang.NoSuchMethodError:org.objectweb.asm.ClassWriter。<init>(I)V7. python3.x - python連oanda的模擬交易api獲取json問題第五問8. javascript - QWebEngineView 如何爬 angular 的動(dòng)態(tài)數(shù)據(jù)?9. docker-machine添加一個(gè)已有的docker主機(jī)問題10. 為什么我ping不通我的docker容器呢???
