【问题标题】:how can i remove x-axis title in google bar chart?如何删除谷歌条形图中的 x 轴标题?
【发布时间】:2014-11-27 13:18:51
【问题描述】:

我尝试使用 google chart api 创建条形图。我想在其中删除 x 轴标题

   <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1.1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Year', 'first six', 'second six'],
          ['2010', 3750, 3800],
          ['2011', 3900, 3850],
          ['2012', 3850, 3900],
          ['2013', 4280, 4160],
          ['2014', 4350, 0000]
        ]);

        var options = {

          width: 400,
          height: 320,
          bar: {groupWidth: "90%"},
          legend: { position: "none" },
        };

        var chart = new google.charts.Bar(document.getElementById('columnchart_material_price'));

        chart.draw(data, options);
      }

这是条形图的代码 我试过了

var options = {
  hAxis: {title: '  ',  titleTextStyle: {color: 'white'}},
}

但这什么也没做。如何删除默认为“年”的 x 轴标题?

【问题讨论】:

    标签: javascript html charts google-visualization


    【解决方案1】:

    以下代码将对您有所帮助。它对我有用。

    var options = {
              width: 400,
              height: 320,
              bar: {groupWidth: "90%"},
              legend: { position: "none" },
              hAxis: { textPosition: 'none' },
    };
    

    【讨论】:

      【解决方案2】:

      尝试将 axes.x.label 设置为 ""。

      希望能帮到你。

      var options = {
          axes: {
               x: {
                   0: { side: 'bottom', label: ""}
               }
          }
      };
      
      chart.draw(data, options);
      

      【讨论】:

        【解决方案3】:
        【解决方案4】:

        您用于声明图表对象的语法似乎不正确,请将行更改为以下行:

        var chart = new google.visualization.BarChart(document.getElementById('columnchart_material_price'));
        

        轴没有预定义的标题。但是,如果您以某种方式看到标题“年份”,那可能是因为数据表的第一列标题。您可以简单地删除它:

        var data = google.visualization.arrayToDataTable([
              ['', 'first six', 'second six'],
              ['2010', 3750, 3800],
              ['2011', 3900, 3850],
              ['2012', 3850, 3900],
              ['2013', 4280, 4160],
              ['2014', 4350, 0000]
        ]);
        

        【讨论】:

          猜你喜欢
          • 2016-09-22
          • 1970-01-01
          • 2023-03-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-03-12
          • 1970-01-01
          相关资源
          最近更新 更多