Can not access chart series datalabels in excel and add in JavaScript

0

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!

javascript
excel
charts
add-in
asked on Stack Overflow Jun 29, 2016 by Danny122 • edited Jun 29, 2016 by (unknown user)

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0