Mark He
Mark He

Reputation: 741

How to display exact value using google.visualization.Table

I'm having trouble displaying exact values using google.visualization.Table

Please see this JSFiddle for my example.

It seems that it defaults to 3 decimal places despite more exact values being provided. I want to show the entire value (e.g. 0.000001).

Below is the data I used:

 data.addRows([
          ['Mike',  {v: 0.01}, true],
          ['Jim',   {v: 0.001},  false],
          ['Alice', {v: 0.0001}, true],
          ['Bob',   {v: 0.00001},  true]
        ]);

Upvotes: 1

Views: 81

Answers (1)

WhiteHat
WhiteHat

Reputation: 61222

the table will display the formatted value by default

using object notation, you can provide both the value (v:) and formatted value (f:)

e.g. --> {v: 0.00001, f: '0.00001'}

see following working snippet...

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

function drawTable() {
  var data = new google.visualization.DataTable();
  data.addColumn('string', 'Name');
  data.addColumn('number', 'Salary');
  data.addColumn('boolean', 'Full Time Employee');
  data.addRows([
    ['Mike',  {v: 0.01, f: '0.01'}, true],
    ['Jim',   {v: 0.001, f: '0.001'},  false],
    ['Alice', {v: 0.0001, f: '0.0001'}, true],
    ['Bob',   {v: 0.00001, f: '0.00001'},  true]
  ]);

  var table = new google.visualization.Table(document.getElementById('table_div'));
  table.draw(data, {showRowNumber: true, width: '100%', height: '100%'});
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="table_div"></div>

Upvotes: 1

Related Questions