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

如何用Google App Script设置Google Sheets嵌入式散点图的系列透明度

Google App Script 设置散点图系列透明度的方法

虽然官方参考文档没有明确列出散点图的透明度配置选项,但可以通过series配置结合pointStyle.fillOpacity来实现,和UI里的设置逻辑对应。

具体代码示例:

function configureScatterChartOpacity() {
  const activeSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const chartData = activeSheet.getDataRange();

  // 创建并配置散点图
  const scatterChart = activeSheet.newChart()
    .setChartType(Charts.ChartType.SCATTER)
    .addRange(chartData)
    .setPosition(2, 2, 0, 0)
    // 针对指定系列设置透明度(0为完全透明,1为完全不透明)
    .setOption('series', {
      0: { // 第一个系列的索引为0
        pointStyle: {
          fillOpacity: 0.3 // 对应UI里的30%透明度
        }
      },
      1: { // 第二个系列
        pointStyle: {
          fillOpacity: 0.7
        }
      }
    })
    .build();

  activeSheet.insertChart(scatterChart);
}
  • fillOpacity的取值范围是0到1,对应UI中的0%到100%透明度
  • 多系列时,只需在series对象中添加对应索引的配置即可
  • 该配置是Google Charts底层支持的,所以即使App Script文档未列出,也能正常生效

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 07:01:14