0

Some options of .setOption when I create an embedded line chart don't work with me.

Options for embedded line chart

For example these:

    .setOption("titlePosition", "in")//accepts Type: string
    .setOption("chartArea.top", 50) //accepts Type: number or string


    //Example: chartArea:{left:20,top:0,width:'50%',height:'75%'} 
    //so I go like:

    var area = {chartArea:{left:20,top:0,width:'50%',height:'75%'}}
    .setOption("chartArea", area)

    //and tried like:

    var area = {left:20,top:0,width:'50%',height:'75%'}
    .setOption("chartArea", area)

  

Nothing works with my embedded line chart.

Here's how I create the chart (it works):

 var chart = sheet.newChart()
        .setChartType(Charts.ChartType.LINE)
        .addRange(range).setTransposeRowsAndColumns(true)
        .setPosition(2, 3, 0, 0)
        .setOption("title", name)
        .build();

    sheet.insertChart(chart);
kiki
  • 199
  • 4
  • 20
  • Possible duplicate of [Google Apps Script: How to set "Use column A as labels" in chart embedded in spreadsheet?](https://stackoverflow.com/questions/13594839/google-apps-script-how-to-set-use-column-a-as-labels-in-chart-embedded-in-spr) – TheMaster Apr 13 '19 at 23:54

1 Answers1

0

the call to setOption is in the wrong place.

the following...

var area = {left:20,top:0,width:'50%',height:'75%'}
.setOption("chartArea", area)

is the same as...

var area = {left:20,top:0,width:'50%',height:'75%'}.setOption("chartArea", area)

you're trying use setOption on a custom object you've created, area,
instead of the chart object.

create area first, then add it to the chart...

var area = {left:20,top:0,width:'50%',height:'75%'};

var chart = sheet.newChart()
    .setChartType(Charts.ChartType.LINE)
    .addRange(range).setTransposeRowsAndColumns(true)
    .setPosition(2, 3, 0, 0)
    .setOption("title", name)
    .setOption("chartArea", area)  // <-- add area
    .build();
WhiteHat
  • 59,912
  • 7
  • 51
  • 133
  • oh sorry I confused you)) my code is like yours, I just wrote the lines together here. Generally I see more examples for chart that uses html but too little explanations of how to use all the methods to the embedded chart. – kiki Apr 15 '19 at 19:22