Google Apps Script Chart Use row 1 as headers

血红的双手。 提交于 2019-12-29 08:00:33

问题


I have the following chart:

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

This code will use the show the first row as part of the data, instead of using it to label the legend. As a side note, if I use asColumnChart instead of line chart, it does the right thing.

How can I tell a chart to use the first row as headers using Google Apps Script?


回答1:


First off - your code is OK. I took a copy and made minor changes to it just to use a single sheet for illustration:

The problem is likely with your data, specifically the first row. Here's that same example, with some of the "Headers" changed from text into numbers. I believe it is behaving in the bad way you're describing.

One more time, but with the numbers in the header forced to be text. (In the spreadsheet, I input them as '4 and '5 - the leading single quote tells Spreadsheet to treat as text.)

Just take a look at the data types in your first row, and make sure that they are Text.



来源:https://stackoverflow.com/questions/14611197/google-apps-script-chart-use-row-1-as-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!