Front-end - Encapsulating the data.format function of d3 encountered problems
高洛峰
高洛峰 2017-05-15 16:56:28
0
1
635

I encountered some problems when using the tooltip.format.value function of c3.js. I need to encapsulate a function myself. A drop-down list is directly presented in the DOM. The user can select the value to set the format.
There are four Options, $, thousands place, accurate to two decimal places or other digits, set both $ and thousands place ($6789,000)

The framework uses angularjs, and I encapsulated a function in the 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. How to set the format of $ and thousand characters at the same time?
2. I don’t know if my function idea is right or not, my thoughts are very confusing at the moment**

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
巴扎黑

1. How to set the format of $ and thousand characters at the same time?
d3.format('$,')(value)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template