Doubt with the Google Charts API

1

I have a bar chart on my system using the google charts API. It is already running, but I have the following problem. I present in the graphs the amounts received and monthly expenses from January to December. You are presenting all the values, however, the problem is in the presentation of the numbers. When I have the value of $ 1500, it shows the value 1.5. Would you like to know if it is possible to change to the national currency format?

<script type="text/javascript">
        google.charts.load('current', {'packages':['bar']});
        google.charts.setOnLoadCallback(drawChart);
        function drawChart() {
            var data = google.visualization.arrayToDataTable([
                ['Mês', 'Receitas', 'Custos e Despesas'],
                ['Janeiro', <?php echo $recebimentoJan; ?>, <?php echo $pagamentoJan; ?>],
                ['Fevereiro', <?php echo $recebimentoFev; ?>, <?php echo $pagamentoFev; ?>],
                ['Março', <?php echo $recebimentoMar; ?>, <?php echo $pagamentoMar; ?>],
                ['Abril', <?php echo $recebimentoAbr; ?>, <?php echo $pagamentoAbr; ?>],
                ['Maio', <?php echo $recebimentoMai; ?>, <?php echo $pagamentoMai; ?>],
                ['Junho', <?php echo $recebimentoJun; ?>, <?php echo $pagamentoJun; ?>],
                ['Julho', <?php echo $recebimentoJul; ?>, <?php echo $pagamentoJul; ?>],
                ['Agosto', <?php echo $recebimentoAgo; ?>, <?php echo $pagamentoAgo; ?>],
                ['Setembro', <?php echo $recebimentoSet; ?>, <?php echo $pagamentoSet; ?>],
                ['Outubro', <?php echo $recebimentoOut; ?>, <?php echo $pagamentoOut; ?>],
                ['Novembro', <?php echo $recebimentoNov; ?>, <?php echo $pagamentoNov; ?>],
                ['Dezembro', <?php echo $recebimentoDez; ?>, <?php echo $pagamentoDez; ?>]
            ]);

            var options = {
                chart: {
                    title: 'Evolução mensal do ano de '+<?php echo $ano; ?>+''
                },
                bars: 'vertical'            
            };

            var chart = new google.charts.Bar(document.getElementById('barchart'));         
            chart.draw(data, options);
        }
    </script>
    
asked by anonymous 09.10.2017 / 21:51

2 answers

1

On line:

google.charts.load('current', {packages: ['corechart']});

Add:

'language': 'pt'

It looks like this:

google.charts.load('current', {packages: ['corechart'],'language': 'pt'})

In the hAxix property, add format: 'currency',

    
18.07.2018 / 21:36
0

Unfortunately the google API does not convert the currency to real. But what can be done is conversion through the code itself. Thus you print the converted value accompanied by the currency symbol R $. ex in PHP:

// repare que o padrão é no formato americano

echo 'R$' . number_format($num, 2); // retorna R$100,000.50


// nosso formato

echo 'R$' . number_format($num, 2, ',', '.'); // retorna R$100.000,50
    
09.10.2017 / 21:58