Farhan
Farhan

Reputation: 431

Google Chart wrapping legend label

I have a Pie chart developed with Google charts, for which the legend labels are too long because of which the legend labels come in multiple lines. As i have dynamic data, I wanted to know if there is a porperty provided for manipulating the legend width.

Please find js fiddle: 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);
  }

Could someone please help me with wrapping the individual legend labels?

Regards, Farhan

Upvotes: 4

Views: 6234

Answers (1)

Tim
Tim

Reputation: 5839

This question was answered by a google employee on google groups. They suggested changing the chartArea options. They also provided an updated JSfiddle.

Upvotes: 1

Related Questions