如何根据最新的2020年1月版本倾斜/旋转Horizo nata /垂直条形图的hAxis和vAxis文本

问题描述 投票:1回答:1

我没有找到关于如何在条形图中实现slantedText选项的任何解决方案。Google是否从最新版本中删除了slantedText属性?

这是我的代码:-

<script src="https://www.gstatic.com/charts/loader.js"></script>
<script>

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

    function drawChart() {
      // Define the chart to be drawn.
      var data = google.visualization.arrayToDataTable([
        ['City', '2010 Population',],
        ['New York City, NY', 8175000],
        ['Los Angeles, CA', 3792000],
        ['Chicago, IL', 2695000],
        ['Houston, TX', 2099000],
        ['Philadelphia, PA', 1526000]
      ]);

      var options = {
        title: 'Population of Largest U.S. Cities',
        chartArea: {width: '50%'},
        legend: { position: "bottom" },
        hAxis: {
          title: 'Total Population',
          minValue: 0,
          slantedText: true,
          slantedTextAngle: 60
        },
        vAxis: {
          title: 'City'
        }
      }

      var chart = new google.charts.Bar(document.getElementById('BarChart'));
      chart.draw(data, options);
    }

</script>
javascript charts google-visualization
1个回答
0
投票

google.charts.Bar被认为是material图表,material图表不支持几个选项,包括...

{hAxis,vAxis,hAxes.*,vAxes.*}.slantedText
{hAxis,vAxis,hAxes.*,vAxes.*}.slantedTextAngle

请参阅Tracking Issue for Material Chart Feature Parity

相反,您需要使用classic图表。

google.visualization.ColumnChart

google.visualization.BarChart
© www.soinside.com 2019 - 2024. All rights reserved.