bozu00
4/22/2019 - 6:45 AM

main.js


function modifyChart() {
  var width = 600;
  var height = 380;
  var backgroundColor = 'white';
  var titleStyle = {color: 'black',  fontSize: 24, bold: true};
  var subtitleStyle = {color: '#666666',  fontSize: 18, bold: false};
  var axisTitlesPosition = 'out';
  var legendStyle = {position: 'top', textStyle: {color: 'black', fontSize: 16}};
  var axis_font_size = 12;
  var hAxisStyle = {title: 'horizontal axis', titleTextStyle: {color: 'black', fontSize: axis_font_size, bold: true}, textStyle: {color: 'black', fontSize: axis_font_size, bold: true}};
  var vAxesStyle = { 0 :{title: 'vertical axis', pointStyle: 'large', titleTextStyle: {color: 'black', fontSize: axis_font_size, bold: true}, textStyle: {color: 'black', fontSize: axis_font_size, bold: true}}, 1: {title: 'vertical axis',  titleTextStyle: {color: 'black', fontSize: axis_font_size, bold: true}, textStyle: {color: 'black', fontSize: axis_font_size, bold: true}}};


  var sheet = SpreadsheetApp.getActiveSheet();


  sheet.getCharts().forEach(function(chart){
  
    chart = chart.modify()
    .setOption('width', width)
    .setOption('height', height)
    .setOption('subtitle', "subtitle hello")
    .setOption('titleTextStyle', titleStyle)
    .setOption('subtitleTextStyle', subtitleStyle)
    .setOption('legend', legendStyle)
    .setOption('axisTitlesPosition', axisTitlesPosition)
    .setOption('backgroundColor', backgroundColor)
    .setOption('hAxis', hAxisStyle)
    .setOption('vAxes', vAxesStyle)
    .setOption('fontName', 'Roboto')
    .setOption('lineWidth', 7)
    .setOption('pointShape', 'circle')
    .setOption('pointSize', 'circle')
    .setOption('selectionMode', 'multiple') //?
    .setOption('series.0.pointSize', 10)
    .setOption('series.0.lineWidth', 4)
    .setOption('series.1.pointSize', 10)
    .setOption('series.1.lineWidth', 4)
    .setOption('series.2.pointSize', 10)
    .setOption('series.2.lineWidth', 4)
    .setOption('series.3.pointSize', 10)
    .setOption('series.3.lineWidth', 4)
    .setOption('series.4.pointSize', 10)
    .setOption('series.4.lineWidth', 4)
    //.setOption('series.0.color', '#ff0000');
    
    setChartTypeOriginSetting(sheet, chart);

    chart = chart.build();
    sheet.updateChart(chart);
  });
}

function setChartTypeOriginSetting(sheet, chart) {

  var chartType = chart.getChartType();
  Logger.log(chartType);

  switch( chartType ) {
    case Charts.ChartType.LINE:
      chart = chart.asLineChart().setPointStyle(Charts.PointStyle.LARGE)
      Logger.log('hello');
      // 実行させたい処理を書く
      break;
    
    case Charts.ChartType.BAR:
      Logger.log('hello');
      chart = chart
        .setOption("series.0.dataLabel", "value")
        .setOption("series.1.dataLabel", "value")
        .setOption("series.2.dataLabel", "value")
        .setOption("series.3.dataLabel", "value")
        .setOption("series.4.dataLabel", "value");
      break;
    
    case Charts.ChartType.COLUMN:
      Logger.log('hello');
      chart = chart
        .setOption("series.0.dataLabel", "value")
        .setOption("series.1.dataLabel", "value")
        .setOption("series.2.dataLabel", "value")
        .setOption("series.3.dataLabel", "value")
        .setOption("series.4.dataLabel", "value")
      break;

  }
}

function onOpen(e) {
  Logger.log("onOpen");
  SpreadsheetApp.getUi().createAddonMenu()
      .addItem('Start', 'showSidebar')
      .addToUi();
}
 
 
function onInstall(e) {
  Logger.log("onInstall");
  onOpen(e);
}
 
 
function showSidebar() {
  Logger.log("showSidebar");
  var ui = HtmlService.createHtmlOutputFromFile('sidebar').setTitle('SFDC');;
  SpreadsheetApp.getUi().showSidebar(ui);
}
 
 
function helllo(userName) {  
  Logger.log(userName);
   
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spreadsheet.getActiveSheet();
  var range = sheet.getRange("A1").setValue(userName);
 
  return "Hello! " + userName;
}