You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Office Script中为数据透视表生成的图表添加Chart Data Table

在Office Script中为数据透视图添加图表数据表格的解决方案

要给已创建的图表添加数据表格,只需在现有代码中添加关键代码,调用图表对象的getDataTable()方法并设置其可见性为true。如果需要自定义数据表格样式(比如是否显示图例键),也可以进一步配置相关属性。

以下是修改后的完整代码:

// Insert pivot chart on sheet sheet1
let chart_1 = sheet1.addChart(ExcelScript.ChartType.columnClustered, newPivotTable.getLayout().getRange());
// Resize and move chart chart_1
chart_1.setLeft(543.75);
chart_1.setTop(24.75);
chart_1.setWidth(468);
chart_1.setHeight(273);
// Change major gridlines visibility for chart chart_1
chart_1.getAxes().getValueAxis().getMajorGridlines().setVisible(false);
// Change minor gridlines visibility for chart chart_1
chart_1.getAxes().getValueAxis().getMinorGridlines().setVisible(false);
// Change title text for chart chart_1
chart_1.getTitle().setText("Active HC");
// 为图表添加数据表格并设置可见
chart_1.getDataTable().setVisible(true);
// 可选:设置数据表格是否显示图例键(按需调整)
chart_1.getDataTable().setShowLegendKey(true);

关键说明

  • chart_1.getDataTable().setVisible(true):启用图表的数据表格显示
  • chart_1.getDataTable().setShowLegendKey(true):可选配置,控制是否在数据表格中显示图例对应标识,不需要可删除该行

内容的提问来源于stack exchange,提问作者Maria Vincent

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 08:10:28