I have a chart in Google Sheets that gets updated with Google Apps Script when a button is hit. Here for example, the color of the lines change when the script is activated.
function change() {
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName("sheet");
var chart = sheet.getCharts()[0];
chart = chart.modify()
.setOption('colors', ['#3465a4', '#A2BEE2', '#76a5af', '#B2CCD2'])
.build();
sheet.updateChart(chart);
}
But I fail to implement a switch to a dashed line - and back again to a non-dashed line. It needs to be done via script, not manually.
I think this might be achieved with the 'security' role and 'uncertainty' attribute as it is documented here: https://developers.google.com/chart/interactive/docs/roles?hl=de#stylerole or with the lineDashStyle documented here: https://developers.google.com/apps-script/chart-configuration-options?hl=de#line-config-options
chart = chart.modify()
.setOption('lineDashStyle', [4,4])
.build();
sheet.updateChart(chart);
But I fail to make it work.
I believe your goal is as follows.
['#3465a4', '#A2BEE2', '#76a5af', '#B2CCD2']
and the dashed lines.In this case, how about the following modification?
chart = chart.modify()
.setOption('colors', ['#3465a4', '#A2BEE2', '#76a5af', '#B2CCD2'])
.build();
sheet.updateChart(chart);
chart = chart.modify()
.setOption('colors', ['#3465a4', '#A2BEE2', '#76a5af', '#B2CCD2'])
.setOption('series', {
0: { lineDashType: 'mediumDash' },
1: { lineDashType: 'mediumDash' },
2: { lineDashType: 'mediumDash' },
3: { lineDashType: 'mediumDash' },
})
.build();
sheet.updateChart(chart);
When this script is run to a sample chart, the following result is obtained.
solid
, dot
, mediumDash
, mediumDashDot
, longDash
, longDashDot
.setOption('series.0.lineDashType', 'mediumDash')
.