5

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"?

SAC
  • 243
  • 3
  • 13

4 Answers4

4

Following code will help you.It works for me.

var options = {
          width: 400,
          height: 320,
          bar: {groupWidth: "90%"},
          legend: { position: "none" },
          hAxis: { textPosition: 'none' },
};
Janith Widarshana
  • 3,213
  • 9
  • 51
  • 73
4

Try set axes.x.label to "".

I hope help.

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

chart.draw(data, options);
Doglas
  • 642
  • 1
  • 11
  • 22
2

Use the option

hAxis: {textPosition: 'none'}

https://developers.google.com/chart/interactive/docs/gallery/linechart#configuration-options

Chloe
  • 25,162
  • 40
  • 190
  • 357
1

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