MaxLines option not applying to legend in Google Stacked Bar chart at bottom?

I am using Google Stacked Bar chart. I found that when my categories span more than one line and the legend is at the top, the legend will wrap across multiple lines controlled by the maxLines option in the hAxis variable.

However, if I move the legend to the bottom, the legend no longer wraps around, but gives a paginated view of the categories. This is the same behavior when the legend is on top and the maxLines option is set to 1.

Here's my fiddle . The top graph has a legend on top and the bottom one has a legend on top ... I did this to make it easy ...

google.load('visualization', '1', {packages: ['corechart', 'bar']});
google.setOnLoadCallback(drawBasic);

function drawBasic() {

      var data = google.visualization.arrayToDataTable([
        ['Genre', 'Fantasy & Sci Fi', 'Romance', 'Mystery/Crime', 'General',
         'Western', 'Literature', { role: 'annotation' } ],
        ['2010', 10, 20, 30, 20, 15, 5, ''],
      ]);

      var options = {
        width: 550,
        height: 160,
          chartArea: {height: '45%' },
        legend: { position: 'top', maxLines: 3 },
        bar: { groupWidth: '55%' },
          hAxis: { maxValue: 100, ticks: [0, 25, 50, 75, 100] },
        isStacked: true
      };

      var chart = new google.visualization.BarChart(document.getElementById('chart_div'));

      chart.draw(data, options);

      var chart2 = new google.visualization.BarChart(document.getElementById('chart2_div'));
    options.legend.position = "bottom";
      chart2.draw(data, options);
    }

      

+3


source to share


1 answer


Uh ... Just found this on google:

The maximum number of lines in the legend. Set this to more than one to add lines to your legend. Note. The exact logic used to determine the actual number of lines displayed is still in motion.

This parameter only works when legend.position is "top".

Type: number Default: 1



https://developers.google.com/chart/interactive/docs/gallery/linechart

+7


source







All Articles