wxr
2022-11-24 2af932533ef851bf983385244e9912976dbd4daa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.mm.android.deviceaddmodule.mobilecommon.widget.linechart.adapter;
 
import java.text.DecimalFormat;
 
/**
 * 报表Y轴单位文案适配器
 * 大于1000的按照1.0k显示
 */
 
public class ReportValueAdapter implements IValueAdapter {
    private DecimalFormat _formatter;
 
    public ReportValueAdapter() {
        _formatter = new DecimalFormat("###,###,###,###.0" + "k");
    }
 
    @Override
    public String value2String(double value) {
        //这里文案的长度会用来计算,负值需要处理
        value = Math.abs(value);
        if (value >= 1000){
            return _formatter.format(value / 1000);
        }else if (value < 10){
            return new DecimalFormat("0.#").format(value);
        }else {
            return new DecimalFormat("###").format(value);
        }
 
    }
}