简体   繁体   中英

Cannot draw correct chart in Google sheets (Google script)

I try to create chart, but I got an issue.

var currentSheet = SpreadsheetApp.getActiveSheet();
var dataSheet_3 = ss.getSheets()[3]; 
var chart = dataSheet.newChart();
chart.setChartType(Charts.ChartType.AREA);
chart.addRange(currentSheet.getRange("E22:E41")); 
chart.addRange(currentSheet.getRange("F22:F41")); 
chart.setPosition(5, 5, 0, 0);
currentSheet.insertChart(chart.build());

How about adding this?

chart.setOption('useFirstColumnAsDomain', true);

Script :

var chart = dataSheet.newChart();
chart.setChartType(Charts.ChartType.AREA);
chart.addRange(currentSheet.getRange("E22:E41")); 
chart.addRange(currentSheet.getRange("F22:F41")); 
chart.setPosition(5, 5, 0, 0);
chart.setOption('useFirstColumnAsDomain', true); // Added
currentSheet.insertChart(chart.build());

Reference :

If I misunderstand your question, I'm sorry.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM