work with value in google charts

2

Well I'm taking a look at how the google graphics works. And I'm not figuring out how to work with men in R $. I need the graph to display the formatted values. Does anyone know how to do this?

<html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script><scripttype="text/javascript">
      google.charts.load("current", {packages:["corechart"]});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     11.57],
          ['Eat',      2],
          ['Commute',  2],
          ['Watch TV', 2],
          ['Sleep',    7]
        ]);

        var options = {
          title: 'My Daily Activities',
          pieHole: 0.4,
        };

        var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="donutchart" style="width: 900px; height: 500px;"></div>
  </body>
</html>
    
asked by anonymous 27.12.2016 / 13:26

1 answer

2

So?

<html>

<head>
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script><scripttype="text/javascript">
    google.charts.load("current", {
      packages: ["corechart"]
    });
    google.charts.setOnLoadCallback(drawChart);

    function drawChart() {
      var data = google.visualization.arrayToDataTable([
        ['Task', 'Hours per Day'],
        ['Work', 11.57],
        ['Eat', 2],
        ['Commute', 2],
        ['Watch TV', 2],
        ['Sleep', 7]
      ]);

      var options = {
        title: 'My Daily Activities',
        pieHole: 0.4,
      };

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

      var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
      chart.draw(data, options, formatter);
    }
  </script>
</head>

<body>
  <div id="donutchart" style="width: 900px; height: 500px;"></div>
</body>

</html>
    
27.12.2016 / 13:37