I am trying to write JavaScript code to generate an excel add-in, using Visual Studio 2015. The aim of the code is to generate a chart and add labels (from text value within the spreadsheet) at specific locations on the chart. The problem with the code I have written seems to be that the chart datalabels
are undefined and can not find a method to access text fields within the spreadsheet for the labels.
var sheet = ctx.workbook.worksheets.getActiveWorksheet();
var sourceData = sheet.getRange("C3:D6");
var chart = ctx.workbook.worksheets.getItem(sheetName).charts.add("xyscatter", sourceData, "auto");
chart.datalabels.visible = true;
chart.datalabels.position = "top";
chart.datalabels.ShowSeriesName = true;
Error:
Exception was thrown at ……
0x800a138f - JavaScript runtime error: Unable to set property 'visible' of undefined or null reference
Any help greatly appreciated!
User contributions licensed under CC BY-SA 3.0