Doubt with Google Charts API

Asked

Viewed 1,342 times

1

I have a bar graph on my system using the google Charts API. It is already working, but I have the following problem. I present in the graphs the amounts received and monthly expenses from January to December. It is presenting all the values, however, the problem is in the presentation of the numbers. When I have the value of R $ 1500,00 it presents the value 1.5. I would 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>

3 answers

1

On the line:

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

Add:

'language': 'pt'

Stay like this:

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

On the estate hAxix, add format: 'currency',

0

Unfortunately the google API does not convert the currency to real ones. However, what can be done is the conversion through the code itself. Thus you print the converted value accompanied by the national 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
  • Unfortunately it did not work, it does not generate the graph...

  • tries this then: var Formatter = new google.visualization.Numberformat( {negativeColor: 'red', negativeParens: true, Pattern: '$###,##'}); Formatter.format(date, 1); Formatter.format(date, 1);

  • The chart doesn’t show either, damn man...

  • Poxa Gustavo, so I don’t have much idea how to help you =( I hope someone answers. I was curious to know what the solution agr.

  • I really appreciate your help... If you find a solution, put here... Thank you

0

//Insira o código "var formatter" nesse local:

var formatter = new google.visualization.NumberFormat({ prefix: 'R$ ', decimalSymbol: ',', groupingSymbol: '.' }); formatter.format(data, 0); formatter.format(data, 1);

var chart = new google.charts.Bar(document.getElementById('barchart'));         
            chart.draw(data, options);
        }
    </script>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.