Google visualization 如何控制google可视化图表中的haxis数据格式?

Google visualization 如何控制google可视化图表中的haxis数据格式?,google-visualization,Google Visualization,我在应用程序中使用Google可视化图表绘制折线图。它工作得很好,除了在hAxis中的一件事输入的数字将自己转换为数千,如下所示。我知道这是因为我试图显示巨大的数字,但我仍然想知道是否有办法解决这个问题 代码 <html> <head> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javas

我在应用程序中使用Google可视化图表绘制折线图。它工作得很好,除了在hAxis中的一件事输入的数字将自己转换为数千,如下所示。我知道这是因为我试图显示巨大的数字,但我仍然想知道是否有办法解决这个问题

代码

<html>
<head>
  <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  <script type="text/javascript">
    google.load('visualization', '1.1', {packages: ['line']});
    google.setOnLoadCallback(drawChart);

    function drawChart() {

      var data = new google.visualization.DataTable();
      data.addColumn('number', 'Degree Level');  
      data.addColumn('number', 'Graduate or professional degree');
      data.addColumn('number', "Bachelor's degree");
      data.addColumn('number', "Associate's degree");
      data.addColumn('number', "High school or vocational training");

      data.addRows([
        [2,  39758,93179, 78578,49141],
        [3,  100747, 300646, 220982,100456],
        [4,  49964,   68022, 21092,6943],
        [5,  150370, 124868, 27120,8204]
      ]);

      var options = {
        chart: {
          title: 'Education Report',
          subtitle: 'distributed by experience'
        },
        width: 900,
        height: 500
      };

      var chart = new google.charts.Line(document.getElementById('linechart_material'));

      chart.draw(data, options);
    }
  </script>
</head>
<body>
  <div id="linechart_material"></div>
</body>
</html>

load('visualization','1.1',{packages:['line']});
setOnLoadCallback(drawChart);
函数绘图图(){
var data=new google.visualization.DataTable();
data.addColumn('number','Degree Level');
数据。添加栏(“编号”、“研究生或专业学位”);
数据。添加栏(“编号”,“学士学位”);
数据。添加栏(“编号”,“副学士学位”);
数据。添加栏(“数字”,“高中或职业培训”);
data.addRows([
[2,  39758,93179, 78578,49141],
[3,  100747, 300646, 220982,100456],
[4,  49964,   68022, 21092,6943],
[5,  150370, 124868, 27120,8204]
]);
变量选项={
图表:{
标题:"教育报告",,
副标题:"凭经验分发"
},
宽度:900,
身高:500
};
var chart=new google.charts.Line(document.getElementById('linechart_material');
图表绘制(数据、选项);
}
输出


有人能告诉我如何使hAxis以数字形式显示吗?

有两种方法可以获得您想要的格式

您可以使用corecharts软件包的版本1:

因此,按如下方式加载包:

//而不是:google.load('visualization','1.1',{packages:['line']});
load('visualization','1',{packages:['corechart']});
将你的图表称为:

//而不是:var chart=new google.charts.Line(document.getElementById('linechart_material');
var chart=new google.visualization.LineChart(document.getElementById('LineChart_material');
你会得到你想要的

见a

或者

使用包的1.1版(您在示例中已经这样做了):

google.load('visualization','1.1',{packages:['line']});
然后在图表选项中指定vAxis格式,如下所示:

vAxis:{格式:'###############',
并以这种方式加载图表,以便将vAxis设置考虑在内:

chart.draw(数据,google.charts.Line.convertOptions(选项));
那也行

见a

这里的问题是,选项的定义方式已从v.1更改为v.1.1。因此,如果要使用v.1.1软件包,必须调用google.charts.Line.convertOptions(),才能正确解释选项