前端 - 封装d3的data.format功能遇到问题
问题描述
在使用c3.js的tooltip.format.value功能的时候碰到一些问题,需要自己封装一个函数,DOM中直接呈现一个下拉列表,用户可以选择值来设定format有四个选项,$,千位符,精确到小数点两位或者其他位,同时设置$和千位符($6789,000)
框架用的是angularjs,我在directive指令里面封装了一个函数
function dataFormat() {var tooltipFormatValue = [];tooltipFormatValue[0] = {’$’:d3.format('$')};tooltipFormatValue[1] = {’thousands separator’:d3.format('s')};//千位符tooltipFormatValue[2] = {’precision’:d3.format('.2f')};//精确小数点后面两位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.怎么同时设定$和千位符格式?2.不知道我的函数思路对不对,目前思绪很混乱**
问题解答
回答1:1.怎么同时设定$和千位符格式?d3.format(’$,’)(value)
相关文章:
1. docker绑定了nginx端口 外部访问不到2. javascript - 关于Js中 this的一道题3. 网页爬虫 - Python:爬虫的中文编码问题?4. javascript - 修改表单多选项时和后台同事配合的问题。5. javascript - H5页面怎么查看console信息?6. mysql - 我的myeclipse一直连显示数据库连接失败,不知道为什么7. ubuntu 远程管理KVM设置问题8. dockerfile - 我用docker build的时候出现下边问题 麻烦帮我看一下9. css - 手机页面在安卓和苹果浏览器显示不同的小小问题10. javascript - vue生成一维码?求助!!!!!急
