我需要将totalValorRequested转换为BRL格式

问题描述 投票:0回答:1
porAntecipacao: function () {
    var formData = tabDashboard.getFormData();
    $.ajax({
        type: "POST",
        url: urlBase + '/TotalAntecipado',
        divLoading: '#graficoPizzaPorAntecipacaoBarra',
        cache: false,
        async: true,
        crossDomain: true,
        processData: false,
        contentType: false,
        xhrFields: {
            withCredentials: true
        },
        data: formData,
        success: resposta => {
            if (resposta.sucesso) {
                var valores = [];

                jQuery.each(resposta.dados.lista,
                    function (name, value) {

                        valores.push([value.pickNome, value.totalValorSolicitado]);
                    });

                var chart2 = c3.generate({
                    bindto: '#graficoPizzaPorAntecipacaoBarra',
                    data: {
                        columns: valores,
                        type: 'bar' 
                    },
                    bar: {
                        width: {
                            ratio: 1 
                        }
                    },
                    axis: {
                        x: {
                            type: 'category' 
                        }
                    },
                    tooltip: {
                        format: {
                            value: function (value, ratio, id) {
                                return value;
                            }
                        }
                    }
                });
            }
        },
    });
},

我需要将其格式化为BRL货币格式,我通过后端接收 公共十进制totalValorSolicitado { get;放; } 公共字符串totalValorSolicitadoFormatado { 获取;放; }

totalValorSolicitadoFormatado 采用 BRL 格式,但图表不接受此字符串格式。有人知道我能做什么吗?

我不知道这是图表接受的格式,还是我做错了什么。

javascript d3.js graphics format
1个回答
0
投票
axis: {
x: {
    type: 'category' 
},
y: {
    tick: {
        format: function (d) {
            var formatar = new Intl.NumberFormat('pt-BR', {
                style: 'currency',
                currency: 'BRL'
            });
            return formatar.format(d);
        }
    }
}



tooltip: {
format: {
    value: function (value, ratio, id) {
        var formatar = new Intl.NumberFormat('pt-BR', {
            style: 'currency',
            currency: 'BRL'
        });
        return formatar.format(value);
    }
}

有效

© www.soinside.com 2019 - 2024. All rights reserved.