javascript 列谷歌图表图例位置问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18184573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 11:00:24  来源:igfitidea点击:

Column Google chart legend position issue

javascriptgoogle-visualization

提问by user2660267

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();

回答by asgallant

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

如果您想要图表顶部​​的图例,您需要将legend.position选项设置为“顶部”:

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

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

并且在使用 ChartWrapper 时,您的选项需要在“options”参数内:

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

回答by SantoshK

we need to add the code inside option section eg. as below :

我们需要在选项部分中添加代码,例如。如下 :

chart1.options = {
        legend: { position: 'top', alignment: 'end' },
        "title": "Sales per month",
        "isStacked": "true",
        // "fill": 20,
        "displayExactValues": true,
        "vAxis": {
            "title": "Sales unit",
            "gridlines": {
                "count": 10
            }
        },
        "hAxis": {
            "title": "Date"
        }
    };

回答by Dev QuickLS

I have used below api to fix the issue :

我已经使用下面的 api 来解决这个问题:

legend.position: ['top', 'bottom']