google 图表中的舍入值

rounding value in google chart

我正在使用 google 图表,当使用非常精确的十进制数时,GG 图表倾向于将其四舍五入为 3 位小数

你可以看到这个例子:

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

  function drawChart() {
    var data = google.visualization.arrayToDataTable([
      ['Age', 'Weight'],
      [ 8,      3.535778],
      [ 4,      5.5],
      [ 11,     14],
      [ 4,      5],
      [ 3,      3.535678],
      [ 6.5,    7]
    ]);

    var options = {
      title: 'Age vs. Weight comparison',
      hAxis: {title: 'Age', minValue: 0, maxValue: 15},
      vAxis: {title: 'Weight', minValue: 0, maxValue: 15},
      legend: 'none'
    };

    var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));

    chart.draw(data, options);
  }

https://jsfiddle.net/00a1sut0/2/

数据中有2个数字,分别是3.535778和3.535678,GG图都标记为3.536

我想显示正确的十进制数

有人知道吗??

使用NumberFormat显示精确值或定义值的模式

在数据table创建后添加此位

var NumberFormat = new google.visualization.NumberFormat(
//You can explore various type of patterns in Documentation
{pattern:'##.#######'}
);
NumberFormat.format(data, 1);

NumberFormat 接受数据 table 和应该具有模式 format(dataTable, columnIndex)

的列

整体代码

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

  function drawChart() {
    var data = google.visualization.arrayToDataTable([
      ['Age', 'Weight'],
      [ 8,      3.535778],
      [ 4,      5.5],
      [ 11,     14],
      [ 4,      5],
      [ 3,      3.535678],
      [ 6.5,    7]
    ]);

   var NumberFormat = new google.visualization.NumberFormat(
   //You can explore various type of patterns in Documentation
   {pattern:'##.#######'}
   );
   NumberFormat.format(data, 1); // Apply formatter to second column

    var options = {
      title: 'Age vs. Weight comparison',
      hAxis: {title: 'Age', minValue: 0, maxValue: 15},
      vAxis: {title: 'Weight', minValue: 0, maxValue: 15},
      legend: 'none'
    };

    var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));

    chart.draw(data, options);
  }

在此处查看演示 - JSFiddle