Is there any way to get number format of ChartPoint using OfficeJS?

Viewed 179

While retrieving point data from Excel.Chart object, value of Chart.Point has General number format by default. Is there any way to get actual number format of Chart.Point value

    const series: Excel.ChartSeriesCollection = chart.series;
        series.load("items");
        await context.sync();
        let chartData = [];
        let seriesIndex = 0;
        for (const seriesItem of series.items) {
          chartData[seriesIndex] = [];
          seriesItem.load(["points", "dataLabels"]);
          await context.sync();
          const points = seriesItem.points;
          points.load("items");
          await context.sync();
          const row = [];
          await points.items.forEach(async (point) => {
            point.load(["dataLabel", "value"]);
            await context.sync();
            row.push(point.value);
          });
          chartData[seriesIndex] = row;
          ++seriesIndex;
        }
        console.log(chartData);
      });

When trying to read a chart as below enter image description here And inserting a new chart from the above read data enter image description here

1 Answers

Unfortunately, Office JS Excel API currently doesn't support get/set numberFormat for chart labels and chart axis labels. therefore, I would suggest that you could submit the request and upvote this request at uservoice

But to unblock your scenario, I have a suggestion that you could set the range numberFormat for the chart source range. once the number format of source data in the range is changed the chart will show the same format as the source range. below is the sample code to set the number format for source data in the given range.

Excel.run(function (ctx) { 
    var numberFormat = "d-mmm";
    var range = ctx.workbook.worksheets.getActiveWorksheet().getRange(rangeAddress);
    range.numberFormat = numberFormat;

});
Related