首页 > 解决方案 > 谷歌饼图更改文本对齐方式

问题描述

这是我的报告,

在此处输入图像描述

如何一一更改我的底部值而不是滚动。

 var options = {
                legend:'bottom',
                is3D: true
                }

标签: javascriptchartsgoogle-visualizationgoogle-pie-chart

解决方案


为了让图例上有多行,
你必须使用图例位置-->'top'
然后你可以增加数量-->maxLines

legend: {
  position: 'top',
  maxLines: 3
},

文档...

legend.maxLines- 图例中的最大行数。将此设置为大于一的数字以向图例添加线条。此选项仅在legend.positionis时有效'top'

请参阅以下工作片段...

google.charts.load('current', {
  packages: ['corechart', 'table']
}).then(function () {
  var data = google.visualization.arrayToDataTable([
    ['category', 'value'],
    ['Category 1', 34],
    ['Category 2', 18.7],
    ['Category 3', 18.6],
    ['Category 4', 18.6],
    ['Category 5', 10]
  ]);

  var pie = new google.visualization.PieChart(document.getElementById('chart-pie'));
  pie.draw(data, {
    legend: {
      position: 'top',
      maxLines: 3
    },
    height: 400,
    is3D: true,
    width: 400
  });
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart-pie"></div>


推荐阅读