Column Google chart legend position issue

user2660267 picture user2660267 · Aug 12, 2013 · Viewed 46.9k times · Source

I want to simply set the marked place legend on top of the graph.
The following is the Google Chart code which does not work:

var wrapper = new google.visualization.ChartWrapper({
  chartType: 'ColumnChart',
  dataTable: Dydata,
  containerId: 'visualization',
  legend: { position: 'bottom', alignment: 'start' },
  width: 520,
  height: 350
});
wrapper.draw();

Answer

asgallant picture asgallant · Aug 12, 2013

If you want the legend at the top of your chart, you need to set the legend.position option to "top":

legend: { position: 'top', alignment: 'start' }

and when using a ChartWrapper, your options need to be inside the "options" parameter:

var wrapper = new google.visualization.ChartWrapper({
    chartType: 'ColumnChart',
    dataTable: Dydata,
    containerId: 'visualization',
    options: {
        legend: { position: 'top', alignment: 'start' },
        width: 520,
        height: 350
    }
});
wrapper.draw();