Google Apps脚本图表vAxis.title不起作用 [英] Google Apps Script Chart vAxis.title not working

查看:73
本文介绍了Google Apps脚本图表vAxis.title不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google Apps Script中为Google Sheets写的东西会生成一个图表.在尝试生成图形时,我想设置轴标题,以便使图表对我本人以外的其他人更易理解.我遇到的问题是,以任何形式设置vAxis.title都不会执行任何操作.生成图表后,将不会创建任何垂直轴标题,而只是空白.

Something I'm writing in Google Apps Script for Google Sheets generates a chart. In trying to generate a graph I'd like to set axis titles so I can make the charts more understandable for people other than myself. The problem I'm having is that setting vAxis.title in any form doesn't do anything. Once the chart is generated no vertical axis title is made, it's just blank.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var range = sheet.getRange(1, 1, sheet.getLastRow(), sheet.getLastColumn());
var chartBuilder = sheet.newChart();

chartBuilder.setChartType(Charts.ChartType.SCATTER)
    .addRange(range)
    .setOption("pointSize", 1)
    .setOption("hAxis.title", "X value")
    .setOption("title", "Output")
    .setOption("vAxis.title", "Y output") //Set vertical axis title (not working)
    .setOption("trendlines", {0: {type: "linear", visibleInLegend: true, showR2: true}})
    .setPosition(1, 1, 150, 0);

sheet.insertChart(chartBuilder.build());

非常感谢您的帮助,谢谢!

Help would be greatly appreciated, Thank you!

推荐答案

此要点为我解决了一个非常相似的问题:

This gist solved a very similar issue for me: https://gist.github.com/tanaikech/4125cc280e15c0fc726cb2fe4f35a3f7

通过setOption("vAxis", {title: "y axis"})设置"vAxis"选项似乎已失败.我尝试了所有类型的设置,但似乎无济于事.

Setting "vAxis" options through setOption("vAxis", {title: "y axis"}) seems to be broken. I tried all types of setting but nothing seemed to work.

但是正如我上面链接的要点所暗示的那样,所有这些设置都可以使用setOption("vAxes", {0: {title: "y axis"}})

But as the gist I link to above suggests, all those settings can be set using setOption("vAxes", {0: {title: "y axis"}})

因此,在您的代码中将.setOption("vAxis.title", "Y output")更改为setOption("vAxes", {0: {title: "Y output"}}).

So in your code change .setOption("vAxis.title", "Y output") to setOption("vAxes", {0: {title: "Y output"}}).

您可以以这种方式设置多个选项,这是我的代码中的一个有效示例:.setOption("vAxes", {0: {title: "Kilograms", viewWindowMode:'explicit',viewWindow: {max:150,min:50}}})

You can set multiple options that way, here is a working example from my code: .setOption("vAxes", {0: {title: "Kilograms", viewWindowMode:'explicit',viewWindow: {max:150,min:50}}})

这篇关于Google Apps脚本图表vAxis.title不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆