Format decimal numbers in Google Chart

Asked

Viewed 714 times

1

I am using Google Chart to bring decimal values from PHP. The structure is as follows:

PHP

<?php
$visualizarChartPagos = $metodos->visualizarPagosChart(date("Y"));
$valor = $visualizarChartPagos[7];
?>

As a result:

4230.00

And on Chart:

function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Mês', 'Pagos', 'Pendentes'],
          ['Jan',  <?php echo $valor; ?>, 400],
          ['Fev',  1170,      460],
          ['Mar',  660,       1120],
          ['Abr',  332,       120],
          ['Mai',  120,       343],
          ['Jun',  324,       545],
          ['Jul',  545,       1243],
          ['Ago',  6534,       5566],
          ['Set',  623,       2221],
          ['Out',  545,       221],
          ['Nov',  667,       326],
          ['Dez',  1030,      540]
        ]);

When I visualize on Chart, it appears that way:

inserir a descrição da imagem aqui

Notice it appears 4,230. How I would make the visualization stay that way 4.230,00? I tried to use the number_format() PHP, but did not accept.

I tried to do it that way, but it didn’t work:

var options = {
          title: 'Dados gráficos do ano de <?php echo date("Y"); ?>',
          hAxis: {format:'##.###,##', title: 'Ano: <?php echo date("Y"); ?>',  titleTextStyle: {color: '#333'}},
          vAxis: {minValue: 0},
          vAxis: {format:'0.00'}
        };

1 answer

1

I was able to solve it this way:

var formatter = new google.visualization.NumberFormat({
              decimalSymbol: ',',
              groupingSymbol: '.',
              prefix: 'R$ '
        });
// Estou aplicando para as colunas 2 e 3
formatter.format(data, 1);
formatter.format(data, 2);

Browser other questions tagged

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