Share via

How to get selected chart element in Excel JS API

Sharon Choong 20 Reputation points
2026-03-05T15:19:50.2333333+00:00

We need to read the data point when a user clicks on one of the parts of a bar chart or pie chart. Something like getSelectedChartElement() that points to the underlying cell range where the data point resides? Or a Chart event whenever a chart element is selected?

Microsoft 365 and Office | Development | Office JavaScript API
0 comments No comments
{count} votes

Answer accepted by question author
  1. Q&A Assist
    2026-03-05T15:20:02.4333333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    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 gives ElementID, Arg1, Arg2 describing the element).
    • ChartSheet.SelectEvent and Chart.SelectEvent in 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:

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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