Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在谷歌图表中显示X轴标题_Javascript_Android_Google Visualization_Column Chart - Fatal编程技术网

Javascript 在谷歌图表中显示X轴标题

Javascript 在谷歌图表中显示X轴标题,javascript,android,google-visualization,column-chart,Javascript,Android,Google Visualization,Column Chart,我想在Android web视图中使用googlecharts显示柱形图的x轴标题。 我试图在中显示x轴标题为Year var data = google.visualization.arrayToDataTable([ ['Year', 'Sales', 'Expenses', 'Profit'], ['2014', 1000, 400, 200], ['2015', 1170, 460, 250], ['2016', 660, 1120, 300],

我想在Android web视图中使用
googlecharts
显示柱形图的x轴标题。 我试图在中显示x轴标题为
Year

var data = google.visualization.arrayToDataTable([
    ['Year', 'Sales', 'Expenses', 'Profit'],
    ['2014', 1000, 400, 200],
    ['2015', 1170, 460, 250],
    ['2016', 660, 1120, 300],
    ['2017', 1030, 540, 350]
  ]);
但它没有显示标题。 完整的代码

<html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      google.charts.load('current', {
  callback: function () {
    drawChart();
    window.addEventListener('resize', drawChart, false);
  },
  packages:['corechart']
});

     function drawChart() {
  var data = google.visualization.arrayToDataTable([
    ['Year', 'Sales', 'Expenses', 'Profit'],
    ['2014', 1000, 400, 200],
    ['2015', 1170, 460, 250],
    ['2016', 660, 1120, 300],
    ['2017', 1030, 540, 350]
  ]);

  var options = {
    animation:{
      duration: 1000,
      easing: 'linear',
      startup: true
    },
    height: 600,
    theme: 'material',
    title: 'Company Performance'
  };

       var chart = new google.visualization.ColumnChart(document.getElementById('columnchart_material'));
  chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="columnchart_material" style="width: 900px; height: 500px;"></div>
  </body>
</html>

google.charts.load('current'{
回调:函数(){
图纸();
window.addEventListener('resize',drawChart,false);
},
软件包:['corechart']
});
函数绘图图(){
var data=google.visualization.arrayToDataTable([
[“年度”、“销售额”、“费用”、“利润”],
['2014', 1000, 400, 200],
['2015', 1170, 460, 250],
['2016', 660, 1120, 300],
['2017', 1030, 540, 350]
]);
变量选项={
动画:{
持续时间:1000,
“线性”,
启动:正确
},
身高:600,
主题:"材料",,
标题:“公司业绩”
};
var chart=new google.visualization.ColumnChart(document.getElementById('ColumnChart_material');
图表绘制(数据、选项);
}
我认为您正在寻找的选项是-->
hAxis.title

    hAxis: {
      title: 'Year'
    },
请参阅以下工作片段

google.charts.load('current'{
回调:函数(){
图纸();
window.addEventListener('resize',drawChart,false);
},
软件包:['corechart']
});
函数绘图图(){
var data=google.visualization.arrayToDataTable([
[“年度”、“销售额”、“费用”、“利润”],
['2014', 1000, 400, 200],
['2015', 1170, 460, 250],
['2016', 660, 1120, 300],
['2017', 1030, 540, 350]
]);
变量选项={
动画:{
持续时间:1000,
“线性”,
启动:正确
},
身高:600,
哈克斯:{
标题:data.getColumnLabel(0)
},
主题:"材料",,
标题:“公司业绩”
};
var chart=new google.visualization.ColumnChart(document.getElementById('ColumnChart_material');
图表绘制(数据、选项);
}


太棒了。但不显示在“[“年”、“销售”、“费用”、“利润”]、”中定义的标题的原因是什么?这些是数据中各列的标题--您可以将这些标题与-->
数据一起使用。getColumnLabel(0)
--请参阅上面更改的答案。。。