Office Scripts : Chart Data Labels "Values From Cells

Tim Smith 0 Reputation points
2024-09-30T20:07:14.6433333+00:00

I am trying to create an Automate Script in Excel that will generate and format chart. I am getting close, but I can't figure out how to set Data Label values. I want the same functionality as the Format Data Label/Label Options/Vale From Cells as shown in the attached image.

This code will show the Y Value as the data label and rotate it 90deg. How can I set this to a cell value instead of the Y Value?

		const thirdSeries = chart_2.addChartSeries();
		YRange = CMBSheet.getRange('G2').getResizedRange(rowCount - 1, 0);
		thirdSeries.setXAxisValues(XRange);
		thirdSeries.setValues(YRange);
		secSName = CMBSheet.getRange('G1').getText();
		thirdSeries.setName(secSName);
		thirdSeries.setHasDataLabels(true);
	
		let thSDataLab = chart_2.getSeries()[3].getDataLabels();
		//thirdSeries.setShowValue(true);
		//thSDataLab.setShowLegendKey(true);
		thSDataLab.setPosition(ExcelScript.ChartDataLabelPosition.top);
		thSDataLab.setTextOrientation(90);

If there is no API for this, is there at least a method I could use to set the text of the data label?

User's image

User's image

Microsoft 365 and Office | Development | Office JavaScript API
Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | Excel | For business | Windows
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.