Google Chart包装图例标签

时间:2016-10-12 06:23:17

标签: charts google-visualization

我有一张用Google图表开发的饼图,图例标签太长,因为图例标签有多行。由于我有动态数据,我想知道是否有一个用于操纵图例宽度的属性。

请找到js小提琴:https://jsfiddle.net/ak8wqt6f/

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

    var data = google.visualization.arrayToDataTable([
      ['Task', 'Hours per Day'],
      ['Work, some text related to work',     11],
      ['Eat, some text related to eat',      2],
      ['Commute, some text related to commute',  2],
      ['Watch TV, some text related to watch tv', 2],
      ['Sleep, some text related to sleep',    7]
    ]);

    var options = {
      title: 'My Daily Activities',
      legend: {
      position: 'right',
      alignment: 'center',
      width: 400,
      floating: true
      },
                chartArea: {
      left: -100,
      width: 450
      }
    };

    var chart = new google.visualization.PieChart(document.getElementById('piechart'));

    chart.draw(data, options);
  }

有人可以帮我包装各个图例标签吗?

此致 尔汉

1 个答案:

答案 0 :(得分:1)

谷歌员工on google groups已回答了这个问题。他们建议更改chartArea选项。他们还提供了updated JSfiddle