简体   繁体   中英

how can i remove x-axis title in google bar chart?

i tried to create a bar chart using google chart api. in which i want to remove the x-axis title

   <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);
      }

this is the code for bar chart i tried

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

but this does nothing . how can i remove x-axis title it is by default "year"?

Try set axes.x.label to "".

I hope help.

var options = {
    axes: {
         x: {
             0: { side: 'bottom', label: ""}
         }
    }
};

chart.draw(data, options);

Following code will help you.It works for me.

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

The syntax you're using to declare chart object doesn't seem right, change the line to the one below:

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

There are no predefined titles for the axis. But if you see the title 'Year' somehow, that's propably because of the data table's first column header. You can simply remove that:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM