jfischer
jfischer

Reputation: 301

Programatically show data labels in Google Spreadsheet Embedded Line Chart

I managed to generate an embedded line chart via a Google App Script.

Current implementation:

var mySheet = SpreadsheetApp.getActive().getSheetByName("Sheet1");
var myDataRange = mySheet.getRange(1, 1, 10, 5);
var chart = mySheet.newChart();
chart.setChartType(Charts.ChartType.LINE);
chart.addRange(myDataRange);
chart.setPosition(1, 1, 0, 0);

var series = {
  0: {
    color: 'blue',
    annotations: {
      textStyle: {
        fontName: 'Times-Roman',
        fontSize: 18,
        color: '#871b47'
      }
    }
  },
  1: { color: '#a9c5e3' }
};
// styling of series works as long as I display data labels manually
chart.setOption('series', series);
var embeddedChart = chart.build();
mySheet.insertChart(embeddedChart);

Now I also want to show data labels in some of the series in the chart. I was able to style existing data labels that I added manually, but I'm not able to display them in a newly created chart only using Apps Script. How can I achieve this?

Upvotes: 2

Views: 1664

Answers (1)

jfischer
jfischer

Reputation: 301

Found the answer here To display data labels for a series I used

var series = {
  0: {
    dataLabel: "value"
  }
};
chart.setOption('series', series);

Upvotes: 4

Related Questions