An Office service that supports add-ins to interact with objects in Office client applications.
The Excel JavaScript API does not provide a chart-level selection event or an API like getSelectedChartElement() to identify which chart element (series, point, slice, etc.) the user clicked, nor to directly map that element back to the underlying cell range.
Available selection APIs in Excel JS are limited to ranges on the worksheet. For example, the API can:
- Select a range programmatically:
await Excel.run(async (context) => { let sheet = context.workbook.worksheets.getActiveWorksheet(); let range = sheet.getRange("B2:E6"); range.select(); await context.sync(); }); - Get the currently selected range:
await Excel.run(async (context) => { let range = context.workbook.getSelectedRange(); range.load("address"); await context.sync(); console.log(`The address of the selected range is "${range.address}"`); });
However, these APIs operate on worksheet ranges, not on chart elements, and there is no documented way in the Excel JavaScript API to:
- Capture a click on a chart element, or
- Determine which series/point/slice was clicked, or
- Resolve that click back to the source
Range.
In contrast, the COM/VSTO/PIA object model for Excel provides chart selection events and helpers such as:
-
ChartEvents_Event.Select/ChartEvents_SelectEventHandler(fires when a chart element is selected and givesElementID,Arg1,Arg2describing the element). -
ChartSheet.SelectEventandChart.SelectEventin VSTO. -
ChartSheet.GetChartElement(x, y, ref ElementID, ref Arg1, ref Arg2)to determine which chart element is at given coordinates.
Those capabilities are not available in the Excel JavaScript API according to the provided documentation.
So with the Excel JS API alone, the scenario of “user clicks a bar/pie slice → code identifies the clicked point and its source range” is not supported.
References:
- Set and get the selected range using the Excel JavaScript API
- Read and write data to the active selection in a document or spreadsheet
- ChartEvents_Event.Select Event
- ChartEvents_SelectEventHandler Delegate
- Chart.SelectEvent Event
- ChartSheet.SelectEvent Event
- ChartSheet.GetChartElement(Int32, Int32, Int32, Int32, Int32) Method