Accessing the secondary (value) axis title

Jan Karel Pieterse 1 Reputation point
2022-05-03T15:10:09.327+00:00

Hi there,

My first question here.
I'm a beginner with office-js, but a very experienced VBA developer.
I'm trying to get the title of the secondary axis of a chart. For the life of me I am unable to find out how.

I've got:

  let chtCt = charts.count;
  for (let i = 0; i < chtCt; i++) {
    let chartOnSht: Excel.Chart = selectedSheet.charts.getItemAt(i);
    chartOnSht.load("name,title,axes");
    chartOnSht.axes.categoryAxis.load("title");
    chartOnSht.axes.valueAxis.load("title");
    await context.sync();

but that valueAxis line only gives me the primary value axis. WHat is the syntax for the secondary one?

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
932 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yunfan Chen 6 Reputation points
    2022-05-11T05:12:39.237+00:00

    Hi,

    if you want get two axes title from one chart, you should try this:

    const sheet = context.workbook.worksheets.getActiveWorksheet();
    let chart = sheet.charts.getItemAt(0);
    chart.load();
    await context.sync();
    chart.axes.categoryAxis.load("title");
    chart.axes.valueAxis.load("title");
    await context.sync();
    console.log(chart.axes.categoryAxis.title.text);
    console.log(chart.axes.valueAxis.title.text);
    

    Gist for reference: https://gist.github.com/e51def0b25c3cfbbcfaf5c42df18ed2a