Vertical labels with google charts API?

2019-01-21 14:00发布

Anyone know how to get x-axis labels to be vertical with google charts API?

I need to fit a lot of labels in a small chart.

Thanks

9条回答
太酷不给撩
2楼-- · 2019-01-21 14:40

It is possible now

var options = {
  title: "Test",
   hAxis: {
        direction:-1,
        slantedText:true,
        slantedTextAngle:90 // here you can even use 180
    }
};
查看更多
迷人小祖宗
3楼-- · 2019-01-21 14:41

The trick is in the chartArea.height = 300 and chartArea.top = 100, height:600

var options = {
    title: 'Motivation and Energy Level Throughout the Day',
    isStacked: true,
    height:600,
    chartArea: {
        height:300,
        top:100,
    },
    hAxis: {
      title: 'Departamentos',
      titleTextStyle: {
        color: '#FF0000',            
      },

      slantedText:true,
      slantedTextAngle:45,

    },
    vAxis: {
      title: 'Kits'
    }
  };
查看更多
Root(大扎)
4楼-- · 2019-01-21 14:44

Yes!

Set hAxis.slantedText to true and then set hAxis.slantedTextAngle=90. Like so...

var ac = new google.visualization.ComboChart(document.getElementById('visualization'));
    ac.draw(data, {
      title : 'Equipment Performance Chart',
      isStacked:true,
      vAxis: {
        viewWindowMode: 'explicit',
        viewWindow: {
            max: 100
            },
        title: "Percentage"
        },
      hAxis: {
        title: "Area",
        slantedText:true,
        slantedTextAngle:90
        },
      seriesType: "bars",

    });
查看更多
爱情/是我丢掉的垃圾
5楼-- · 2019-01-21 14:46

this is a bit of an old thread. but i was searching for this myself and came across this...

https://developers.google.com/chart/interactive/docs/gallery/areachart#Configuration_Options

Look for: hAxis.slantedTextAngle and hAxis.slantedText. Set your angle to 90 for vertical display (or anything in between for a slant).

查看更多
做个烂人
6楼-- · 2019-01-21 14:48

Another possible way you can "work around" this issue is to add an x axis:

chxt=x,y

could change to:

chxt=x,y,x

(Make sure anything you did to your original x axis has the same applied) then set your labels every other in one axis and every other offset by one in the other x axis (or every third depending on how long your labels are).

chx1=0:|Alpha||Gamma||Epsilon||Eta|2:||Beta||Delta||Zeta

Note the two || for an empty label between. That way on your graph the labels switch off axises and you have a little more space:

Alpha    Gamma    Epsilon    Eta
    Beta      Delta      Zeta
查看更多
成全新的幸福
7楼-- · 2019-01-21 14:52

Diagonal Text here. This is my way of doing it, I hope it will help them.

https://jsfiddle.net/8tvm9qk5/

The code:

  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  <div id="chart_div"></div>

and

google.charts.load('current', {packages: ['corechart', 'bar']});
google.charts.setOnLoadCallback(drawStacked);

function drawStacked() {
      var data = new google.visualization.DataTable();
      data.addColumn('string', 'Departamentos');
      data.addColumn('number', 'Entregados');
      data.addColumn('number', 'En Stock');

      data.addRows([
        ['abdasdasa', 925, 786],
        ['bbdasdas', 652, 156],
        ['cbdasdas', 300, 200],
        ['ddasdasb', 925, 786],
        ['edasdb', 652, 156],
        ['fasdasb', 300, 200],
        ['gdasdasdb', 925, 786],
        ['abdasdasa', 925, 786],
        ['bbdasdas', 652, 156],
        ['cbdasdas', 300, 200],
        ['ddasdasb', 925, 786],
        ['edasdb', 652, 156],
        ['fasdasb', 300, 200],
        ['gdasdasdb', 925, 786]


      ]);

      var options = {
        title: 'Motivation and Energy Level Throughout the Day',
        isStacked: true,
        height:600,
        chartArea: {
            height:300,
          top:100,
        },
        hAxis: {
          title: 'Departamentos',
          titleTextStyle: {
            color: '#FF0000',            
          },

          slantedText:true,
          slantedTextAngle:45,

        },
        vAxis: {
          title: 'Kits'
        }
      };

      var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
      chart.draw(data, options);
    }
查看更多
登录 后发表回答