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

Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,882 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
985 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,891 questions
0 comments No comments
{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.