谷歌图表:修复未捕获(承诺)错误: [英] google chart:fix the Uncaught (in promise) Error:

查看:265
本文介绍了谷歌图表:修复未捕获(承诺)错误:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用谷歌图表我绘制了一个这样的折线图。



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



从db获取图表数据。根据某些图表数据,我无法在下面的例子中,我更改了图表数据,并且由于jfidle代码行57中的js erros没有显示图形,所以图表没有显示出来。



/ p>

即使图表数据发生变化,我也会在下面的方法中遇到更多脚本问题。

  function toolTipVal(dt,row,index1,index2){
label1 = dt.getColumnLabel(index1).split(\\\
);
label2 = dt.getColumnLabel(index2).split(\\\
);
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未捕获(承诺中)错误:无效的行索引-1。应在上述方法行中的范围[0-799]中

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



如何修改上述基于这些图表数据的方法

解决方案行是一个零索引值。您正在调用

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



而不测试是否不是第一个。



我并不完全忽略逻辑,但我想你必须为第一个节点的工具提示添加一些逻辑。


$

您将在每次
$ b dt.getValue(row,index1)=== null



碰巧对于行== 0 是真的。


using google chart i plotted a line chart like this.

In the graph i have created a custom tool tip as shown in the jfiddle. In the above graph there is no problems with displaying the chart with tool tip.

Am fetching chart data from db.Based on some chart data am not able to render the chart due to some js erros.

in the below example i changed the chart data and graph is not diplaying due to js erros in line 57 of jfidle code

im facing more script issues inside below method whenever the chart data varies.

  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];
          }; 

If am using the second data set in jfiddle am getting follwoing js error

 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); due to this graph is not rendering in the UI.

How can i modify the above method based on these chart data's

解决方案

row is a zero indexed value. You are calling

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

without testing if the row isn't the first.

I don't understend completely the logic but I guess that you have to add some logic for the tooltip of the first node.

You will get into that exception every time the

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

happens to be true for row == 0.

这篇关于谷歌图表:修复未捕获(承诺)错误:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆