移动端JS放在chart里不生效放在report里的图表里生效

请问如下js为何直接放在chart里不生效 ,但是放在report里的图表里又生效,移动端版本11.0.28

 function a(){

 let name = this.name;

 let value = this.value;

 let matched = name.match(/\((.*)\)/)[1];

 name = name.replace(`(${matched})`, '');

 let desc = `

${name}`;

 matched.split(',').forEach(text => {

  desc += `

${text}`

 });

 desc += `

*人口数:${value}`;

 return "

" + desc + "

";

}

------------------------------------

 function a() {

  const chart = FR.Chart.WebUtils.getChart("chart0"); // 替换为实际图表ID

  const name = chart.getSelectedData().name; // 使用图表API获取数据

  const value = chart.getSelectedData().value;

  let matched = name.match(/\((.*)\)/)[1];

  name = name.replace(`(${matched})`, '');

  let desc = `

${name}`;

  matched.split(',').forEach(text => {

  desc += `

${text}`

  });

  desc += `

人口数:${value}`;

  return "

" + desc + "

";

 }

FineReport ran1025 发布于 4 天前 (编辑于 4 天前
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
ScyalcireLv7高级互助
发布于4 天前(编辑于 4 天前
  • 报表中的图表通过 contentPane.curLGP 获取单元格上下文,而独立图表直接使用 this 可能未绑定正确对象‌

  • 独立图表需通过 FR.Chart.WebUtils.getChart() 显式获取图表对象‌

setTimeout(function() {
    const chart = FR.Chart.WebUtils.getChart("chart0");
    if(chart) {
        const name = chart.getSelectedData().name;
        const value = chart.getSelectedData().value;
        
        let matched = name.match(/\((.*)\)/)^4^;
        name = name.replace(`(${matched})`, '');
        let desc = `${name}`;
        
        matched.split(',').forEach(text => {
            desc += `${text}`;
        });
        
        desc += `人口数:${value}`;
        return desc;
    }
}, 500);
  • ran1025 ran1025(提问者) 修改成这样 还是不生效呢,实际图表id也为chart0:
    function a() {
    const chart = FR.Chart.WebUtils.getChart("chart0"); // 替换为实际图表ID
    const name = chart.getSelectedData().name; // 使用图表API获取数据
    const value = chart.getSelectedData().value;

    let matched = name.match(/\((.*)\)/)[1];
    name = name.replace(`(${matched})`, '');
    let desc = `

    ${name}

    `;
    matched.split(',').forEach(text => {
    desc += `

    ${text}

    `
    });
    desc += `

    人口数:${value}

    `;
    return "
    " + desc + "
    ";
    }
    2025-07-18 11:31 
  • Scyalcire Scyalcire 回复 ran1025(提问者) 你要在最外层加一段延迟函数setTimeout(function() {}, 500);
    2025-07-18 12:02 
  • Scyalcire Scyalcire 回复 ran1025(提问者) 新的代码我重新写在上面了
    2025-07-18 12:03 
  • ran1025 ran1025(提问者) 回复 Scyalcire 如果还是不生效 是不是FR.Chart.WebUtils.getChart("chart0")对移动端版本11.0.28 不支持的原因?
    2025-07-18 14:25 
最佳回答
0
大王在此Lv5见习互助
发布于4 天前

这种改成英文下的双引号试试

image.png

  • 3关注人数
  • 45浏览人数
  • 最后回答于:4 天前
    请选择关闭问题的原因
    确定 取消
    返回顶部