首页 文章

谷歌图表:修复未捕获(承诺)错误:

提问于
浏览
1

使用谷歌图表我绘制了这样的折线图 .

在图表中,我创建了一个自定义工具提示,如jfiddle中所示 . 在上图中,使用工具提示显示图表没有问题 .

从db获取图表数据 . 基于某些图表数据由于某些js错误而无法呈现图表 .

在下面的例子中我更改了图表数据,并且图表不是由于jfidle代码的第57行中的js erros而进行diplaying

当图表数据变化时,我在下面的方法中面临更多脚本问题 .

function toolTipVal(dt, row, index1, index2) {           
                 label1 = dt.getColumnLabel(index1).split("\n");
                 label2 = dt.getColumnLabel(index2).split("\n");
                 yValue1 =0; yValue2 =0;           
                  if (dt.getValue(row, index1) === null ) {
                    yValue1 = dt.getFormattedValue(row -1, index1);               
                  } 
                  else {
                    yValue1 = dt.getFormattedValue(row, index1);                  
                  }            
                  if (dt.getValue(row, index2) === null) {
                    if (row > 0) {
                      yValue2 = dt.getFormattedValue(row - 1, index2);
                    }
                  } else {
                    yValue2 = dt.getFormattedValue(row, index2);
                  }              
                  return [yValue1, yValue2, label1, label2];
          };

如果我在jfiddle中使用第二个数据集,则会发现以下js错误

jsapi_compiled_default_module.js:74 Uncaught (in promise) Error: Invalid row index -1. Should be in the range [0-799] in above methodline

yValue1 = dt.getFormattedValue(row -1, index1); 由于此图表未在UI中呈现 .

如何根据这些图表数据修改上述方法

1 回答

  • 1

    row 是零索引值 . 你在打电话

    yValue1 = dt.getFormattedValue(row -1, index1);

    如果 row 不是第一个,则不进行测试 .

    我没有完全记录逻辑,但我想你必须为第一个节点的工具提示添加一些逻辑 .

    你每次都会进入那个例外

    dt.getValue(row, index1) === null

    对于 row == 0 来说恰好是真的 .

相关问题