如何修复 JavaScript 代码中的“Uncaught TypeError: Cannot read property 'range' of undefined”?

问题描述

这里是 Javascript 的新手。 我目前正在尝试绘制从 vis.js 中的 Json 文件读取的 x、y 和 z 坐标中的数据。 代码如下。

<!doctype html>
<html>
<head>
  <title>Graph 3D | Animation</title>

  <style type="text/css">
    body {
      font: 10pt arial;
    }
  </style>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script type="text/javascript" src="./standalone/umd/vis-graph3d.js"></script>
  <script type="text/javascript">
    var data = null;
    var graph = null;

    // Called when the Visualization API is loaded.
    function drawVisualization() {
      console.log('drawVisualization >>')
      coor = new vis.DataSet();
      $(document).ready(function(){
        $.getJSON('./server/Output/202176112622.json',function(data){
            $.each(data,function(i,item){
                var x,y,z;
                coor.add([
                  {x:item.x,y:item.y,z:item.z}
                ]);
            });
        });
      });
      
      // specify options
      var options = {
        width:  '800px',height: '600px',style: 'surface',showPerspective: true,showGrid: true,showShadow: false,// showAnimationControls: false,keepAspectRatio: true,verticalRatio: 0.5,animationInterval: 100,// milliseconds
        animationPreload: true
      };
      // create our graph
      var container = document.getElementById('mygraph');
      graph = new vis.Graph3d(container,coor,options);
    };    
  </script>
  
</head>

<body onload="drawVisualization();">
<div id="mygraph"></div>

<div id="info"></div>
<p>Hello sanion</p>
</body>
</html>

但是,由于出现错误,我似乎无法绘制图形。

Uncaught TypeError: Cannot read property 'range' of undefined
    at Graph3d._setScale (Graph3d.js:197)
    at Graph3d._initializeRanges (Graph3d.js:365)
    at Graph3d._readData (Graph3d.js:636)
    at Graph3d.setData (Graph3d.js:648)
    at new Graph3d (Graph3d.js:186)
    at drawVisualization (04_animation.html:49)
    at onload (04_animation.html:55)

这是我收到错误的部分行。

Graph3d.prototype._setScale = function() {
  this.scale = new Point3d(
    1 / this.xrange.range(),1 / this.yRange.range(),1 / this.zRange.range()
  );

我需要在代码中以某种方式定义 range 的参数吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)