使用咨询 | 图表无法使用筛选传递的变量

* 描述问题

我创建了一个图表,使用自定义的sql,我希望使用筛选的功能,然后我增加了一个筛选的区块,但是我无法在sql这里插入我新增的筛选变量。我在筛选条件设置了各种类型,自定义字段,和区块绑定的字段都不行。

在操作 xxx 界面时,遇到 yyy 报错。

* 运行环境

服务端

  • NocoBase 应用版本(Docker 填写镜像 tag,如 latest / 1.6.13 等):v2.2.0-alpha.8
  • 数据库(Postgres / MySQL 等)及版本:postgres
  • 部署方式(Docker / Create-nocobase-app / 源码):docker
  • 操作系统(Debian / Ubuntu / WinServer 等)及版本:wsl
  • NodeJS 版本(如使用 Create-nocobase-app 或 源码部署的请提供):

客户端

  • 操作系统(Windows / macOS / iOS / Android 等)及版本:window
  • 浏览器(Chrome / Safari 等)及版本:edg

* 复现步骤

我的sql:

这里没有添加筛选条件,我是想增加一个负责人的过滤,只查询指定负责人的数据。

-- 按负责人+完成月份聚合已完成工作项的故事点
SELECT 
  TO_CHAR(TO_TIMESTAMP(update_status_at::double precision / 1000), 'YYYY-MM') AS "月",
  assigned_to_name AS "负责人",
  ROUND(SUM(story_points), 1) AS "点数",
  COUNT(*) AS "数量"
FROM yunxiao_work_items
WHERE story_points > 0
  AND (status_name = '已完成' OR status_name = '已关闭')
  AND update_status_at >= 1777564800000  -- 2026-05-01 +08:00
  AND update_status_at <  1785513600000  -- 2026-08-01 +08:00
  AND update_status_at > 0
GROUP BY "月", "负责人"
ORDER BY "月", "点数" DESC;

​

下面是图表

const data = ctx.data.objects || [];
const months = [...new Set(data.map(d => d['月']))].sort();
const persons = [...new Set(data.map(d => d['负责人']))];

// 按总点数排序取前6
const totals = {};
persons.forEach(p => {
  totals[p] = data.filter(d => d['负责人'] === p)
                  .reduce((s, d) => s + Number(d['点数'] || 0), 0);
});
const top6 = persons.sort((a, b) => totals[b] - totals[a]).slice(0, 10);

function getVal(person, month) {
  const found = data.find(d => d['负责人'] === person && d['月'] === month);
  return found ? Number(found['点数']) : 0;
}

const colors = ['#5470c6','#91cc75','#ee6666','#fac858','#73c0de','#8a2be2'];

return {
  title: { text: '各负责人已完成故事点趋势', left: 'center' },
  tooltip: { trigger: 'axis' },
  legend: { bottom: 0, textStyle: { fontSize: 10 }, itemGap: 4 },
  grid: { left: 50, right: 20, top: 40, bottom: 55 },
  xAxis: { type: 'category', data: months, name: '月份', axisLabel: { fontSize: 10 } },
  yAxis: { type: 'value', name: '故事点' },
  series: top6.map(function(p, i) {
    return {
      name: p,
      type: 'line',
      data: months.map(m => getVal(p, m)),
      symbol: 'circle',
      symbolSize: 5,
      lineStyle: { color: colors[i], width: 2.5 },
      itemStyle: { color: colors[i] },
      label: {
        show: true,
        fontSize: 9,
        color: colors[i],
        formatter: function(v) { return v.value > 0 ? v.value : ''; }
      }
    };
  })
};

​

预期行为

期待不报错。

截图

截图1:

日志

替换日志内容
  1. 在筛选表单中定义筛选字段
  2. 在页面事件流中定义表单变量
  3. 在图表中使用表单变量
  4. 当使用筛选表单进行筛选时,刷新图表区域

我们这边也有类似的问题,就是虽然文档有写,但是大部分人看不懂 :joy:
可能要从文档上想想办法