Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script Google应用程序脚本图表使用第1行作为标题_Google Apps Script_Google Visualization_Google Sheets - Fatal编程技术网

Google apps script Google应用程序脚本图表使用第1行作为标题

Google apps script Google应用程序脚本图表使用第1行作为标题,google-apps-script,google-visualization,google-sheets,Google Apps Script,Google Visualization,Google Sheets,我有以下图表: var ss = ... // get sheet var chart = ss.newChart().asLineChart(); chart.setTitle("My Title"); chart.addRange(dataSheet.getRange(1, 1, ss.getLastRow(), 4)); chart.setColors(["#3c78d8", "#a61c00", "#38761d"]); chart.setXAxisTitle("X Title"); c

我有以下图表:

var ss = ... // get sheet
var chart = ss.newChart().asLineChart();
chart.setTitle("My Title");
chart.addRange(dataSheet.getRange(1, 1, ss.getLastRow(), 4));
chart.setColors(["#3c78d8", "#a61c00", "#38761d"]);
chart.setXAxisTitle("X Title");
chart.setYAxisTitle("Y Title");
chart.setPosition(1, 1, 0, 0);
chart.setCurveStyle(Charts.CurveStyle.SMOOTH);
ss.insertChart(chart.build()); 
此代码将使用显示第一行作为数据的一部分,而不是使用它来标记图例。作为旁注,如果我使用柱形图而不是折线图,它会做正确的事情


如何使用Google Apps脚本告诉图表使用第一行作为标题?

首先-您的代码没有问题。我拿了一份复印件,对它做了一些小改动,只是为了用一张纸来说明:

问题可能出在您的数据上,特别是第一行。这里是同一个例子,一些“标题”从文本变成了数字。我相信它的行为和你描述的不一样

再一次,但标题中的数字必须是文本。(在电子表格中,我将其输入为
'4
'5
——前面的单引号告诉电子表格将其视为文本。)


只需查看第一行中的数据类型,并确保它们是文本

首先-您的代码正常。我拿了一份复印件,对它做了一些小改动,只是为了用一张纸来说明:

问题可能出在您的数据上,特别是第一行。这里是同一个例子,一些“标题”从文本变成了数字。我相信它的行为和你描述的不一样

再一次,但标题中的数字必须是文本。(在电子表格中,我将其输入为
'4
'5
——前面的单引号告诉电子表格将其视为文本。)


只需查看第一行中的数据类型,并确保它们是文本

那正是我的问题。谢谢。从今天起,这种方法不再适用于我。这正是我的问题。谢谢。从今天起,这种方法不再适用于我。